Changeset 3193 in MondoRescue


Ignore:
Timestamp:
Sep 29, 2013, 9:31:34 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • Finish with backports from 3.1 for now. Still some work to do, but we will now make that version compile and work again and serve as a base

so the gettext patch can be added

Location:
branches
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • branches/3.1/mondo/src/include/mr_str.h

    r2421 r3193  
    1616
    1717extern char *mr_strtok(char *instr, const char *delims, int *lastpos);
    18 extern char *mr_stresc(char *instr, char *toesc, const char escchr);
    19 extern char *mr_date(void);
     18extern char *mr_stresc(char *instr, char *toesc, const char escchr, const char specialchr);
     19extern inline char *mr_date(void);
    2020extern void mr_strip_spaces(char *in_out);
    2121extern void mr_strip_char(char *in_out, char *caracs);
  • branches/3.1/mondo/src/include/my-stuff.h

    r3147 r3193  
    339339#define ARCH_THREADS 2          ///< The number of simultaneous threads running afio in the background.
    340340#define ARCH_BUFFER_NUM (ARCH_THREADS*4)    // Number of permissible queued afio files
     341#define FORTY_SPACES "                                         "    ///< 40 spaces.
    341342#define DO_MBR_PLEASE "/tmp/DO-MBR-PLEASE"
    342343#define MONDO_MNTLISTCHG "/tmp/mountlist.changed"
  • branches/3.1/mondo/src/lib/mr_str.c

    r3147 r3193  
    1212
    1313#include "mr_mem.h"
     14
     15// to get bool type
     16#define _MY_STUFF_H_
     17#include "my-stuff.h"
    1418 
    1519/**
     
    6670 * @note this function allocates memory that needs to be freed by caller
    6771 **/
    68 char *mr_stresc(char *instr, char *toesc, const char escchr) {
     72char *mr_stresc(char *instr, char *toesc, const char escchr, const char specialchr) {
    6973    char *inptr = NULL;
    7074    char *retstr = NULL;
     
    7276    char *escptr = NULL;
    7377    int cnt = 0;
     78    bool found = FALSE;
    7479
    7580    inptr = instr;
    76 
    7781    // Count how many characters need escaping.
    7882    while (*inptr != '\0') {
     
    8286                // Found it, skip the rest.
    8387                cnt++;
     88                // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars
     89                if (*inptr == specialchr) {
     90                    cnt += 2;
     91                }
    8492                break;
    8593            }
     
    8896        inptr++;
    8997    }
     98
    9099    inptr = instr;
    91 
    92100    retstr = (char *) mr_malloc(strlen(inptr) + cnt + 1);
    93101    retptr = retstr;
     
    99107            if (*inptr == *escptr) {
    100108                // Found it, skip the rest.
    101                 *retptr = escchr;
    102                 retptr++;
     109                // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars
     110                if (*inptr == specialchr) {
     111                    *retptr = specialchr;
     112                    retptr++;
     113                    *retptr = escchr;
     114                    retptr++;
     115                    found = TRUE;
     116                } else {
     117                    *retptr = escchr;
     118                    retptr++;
     119                }
    103120                break;
    104121            }
     
    108125        retptr++;
    109126        inptr++;
     127        if (found) {
     128            // finish to put the remaining specialchr
     129            *retptr = specialchr;
     130            retptr++;
     131            found = FALSE;
     132        }
    110133    }
    111134    *retptr = '\0';
     
    114137}
    115138
    116 /**
    117  * Remove all characters in caracs from begining and end of string @p in_out
    118  * @param in_out The string to strip char characters from (modified).
     139/* Return a string containing the date */
     140char *mr_date(void) {
     141   
     142    time_t tcurr;
     143
     144    tcurr = time(NULL);
     145    return(ctime(&tcurr));
     146}
     147
     148/* Return an allocated string containing the date
     149char *mr_date(void) {
     150   
     151    time_t tcurr;
     152    char *tmp = NULL;
     153
     154    tcurr = time(NULL);
     155    mr_asprintf(tmp, "%s", ctime(&tcurr));
     156    mr_chomp(tmp);
     157    return(tmp);
     158}
    119159 */
    120 void mr_strip_char(char *in_out, char *caracs) {
    121     int i = 0;
    122     int j = 0;
    123     int length = 0;
    124 
    125     if (caracs == NULL) {
    126         return;
    127     }
    128     if (in_out == NULL) {
    129         return;
    130     }
    131     length = (int)strlen(in_out);
    132 
    133     /* Skip initial caracs */
    134     for (i = 0; index(caracs, in_out[i]) != NULL && i < length ; i++);
    135 
    136     /* Shift the string to the begining if needed */
    137     if (i != 0) {
    138         for (j = 0; i < length ; i++, j++) {
    139             in_out[j] = in_out[i];
    140         }
    141         /* Erase the end of the string if needed */
    142         j++;
    143         in_out[j] = '\0';
    144     }
    145 
    146     /* Skip final spaces and special chars */
    147     for (i = (int)strlen(in_out) - 1; i >= 0  && index(caracs, in_out[i]) != NULL; i--);
    148 
    149     /* The string now ends after that char */
    150     i++;
    151     in_out[i] = '\0';
    152 }
    153160
    154161/**
     
    158165 */
    159166void mr_strip_spaces(char *in_out) {
    160 
    161     int i;
    162     char *tmp = NULL;
    163 
    164     mr_asprintf(tmp, "");
    165 
    166     /* Build the string of char to avoid: ctrl char up to space*/
    167     for (i = 0; i <= ' '; i++) {
    168         mr_strcat(tmp, "%c", i);
    169     }
    170    
    171     mr_strip_char(in_out, tmp);
    172     mr_free(tmp);
    173 }
     167    int i = 0;
     168    int j = 0;
     169    size_t length;
     170
     171    if (in_out == NULL) {
     172        return;
     173    }
     174    length = strlen(in_out);
     175
     176    /* Skip initial spaces and special chars */
     177    for (i = 0; in_out[i] <= ' ' && i < (int)length ; i++);
     178    /* Shift the string to the begining if needed */
     179    if (i != 0) {
     180        for (j = 0; i < (int)length ; i++, j++) {
     181            in_out[j] = in_out[i];
     182        }
     183        /* Erase the end of the string if needed */
     184        j++;
     185        in_out[j] = '\0';
     186    }
     187
     188    /* Skip final spaces and special chars */
     189    for (i = (int)strlen(in_out) - 1; i >= 0  && in_out[i] <= ' '; i--);
     190
     191    /* The string now ends after that char */
     192    i++;
     193    in_out[i] = '\0';
     194}
     195
    174196
    175197/*
    176198 * Remove '\n' char from both sides of @p in_out.
    177199 * @param in_out The string to strip characters from (modified).
    178  */
     200
    179201void mr_chomp(char *in_out) {
    180202
    181203    mr_strip_char(in_out, "\n");
    182204}
    183 
    184 /* Return an allocated string containing the date */
    185 char *mr_date(void) {
    186    
    187     time_t tcurr;
    188     char *tmp = NULL;
    189 
    190     tcurr = time(NULL);
    191     mr_asprintf(tmp, "%s", ctime(&tcurr));
    192     mr_chomp(tmp);
    193     return(tmp);
    194 }
    195 
    196 
     205*/
     206
     207/**
     208 * Remove all characters in caracs from begining and end of string @p in_out
     209 * @param in_out The string to strip char characters from (modified).
     210
     211void mr_strip_char(char *in_out, char *caracs) {
     212    int i = 0;
     213    int j = 0;
     214    size_t length = 0;
     215
     216    if (caracs == NULL) {
     217        return;
     218    }
     219    if (in_out == NULL) {
     220        return;
     221    }
     222    length = strlen(in_out);
     223
     224    /* Skip initial caracs */
     225    for (i = 0; index(caracs, in_out[i]) != NULL && i < (int)length ; i++);
     226
     227    /* Shift the string to the begining if needed */
     228    if (i != 0) {
     229        for (j = 0; i < (int)length ; i++, j++) {
     230            in_out[j] = in_out[i];
     231        }
     232        /* Erase the end of the string if needed */
     233        j++;
     234        in_out[j] = '\0';
     235    }
     236
     237    /* Skip final caracs */
     238    for (i = (int)strlen(in_out) - 1; i >= 0  && index(caracs, in_out[i]) != NULL; i--);
     239
     240    /* The string now ends after that char */
     241    i++;
     242    in_out[i] = '\0';
     243}
     244*/
     245
  • branches/3.1/mondo/src/mondoarchive/mondoarchive.c

    r3148 r3193  
    3737extern t_bkptype g_backup_media_type;
    3838extern int g_loglevel;
     39
    3940extern char *g_magicdev_command;
    4041
     
    101102    log_msg(7, "Seven...");
    102103    log_msg(8, "Eight...");
     104    printf("See %s for details of backup run.\n", MONDO_LOGFILE);
    103105}
    104106
     
    164166    FILE *fin = NULL;
    165167
     168/* Make sure I'm root; abort if not */
     169    if (getuid() != 0) {
     170        fprintf(stderr, "Please run as root.\r\n");
     171        exit(127);
     172    }
     173
     174/* If -V, -v or --version then echo version no. and quit */
     175    if (argc == 2 && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V") || !strcmp(argv[argc - 1], "--version"))) {
     176        printf("mondoarchive v%s\nSee man page for help\n", PACKAGE_VERSION);
     177        exit(0);
     178    }
     179
     180/* Initialize variables */
     181
    166182    printf("Initializing...\n");
     183
     184    init_bkpinfo();
     185
     186    /* Memory allocation is done in those functions */
     187    malloc_libmondo_global_strings();
    167188
    168189    /* initialize log file with time stamp */
    169190    unlink(MONDO_LOGFILE);
    170     tmp = mr_date();
    171     log_msg(0, "Time started: %s", tmp);
    172     mr_free(tmp);
    173 
    174     init_bkpinfo();
    175 
    176     /* Memory allocation is done in those functions */
    177     malloc_libmondo_global_strings();
     191    log_msg(0, "Time started: %s", mr_date());
     192
    178193    if (argc == 1) {
    179194        g_text_mode = FALSE;
     
    188203    }
    189204    setup_newt_stuff();
    190 
    191     /* Make sure I'm root; abort if not */
    192     if (getuid() != 0) {
    193         fatal_error("Please run as root.\n");
    194     }
    195 
    196     /* If -V, -v or --version then echo version no. and quit */
    197     if (argc == 2 && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V") || !strcmp(argv[argc - 1], "--version"))) {
    198         printf("mondoarchive v%s\nSee man page for help\n", PACKAGE_VERSION);
    199         finish(0);
    200     }
    201 
    202205
    203206    /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
     
    449452
    450453    /* finalize log file with time stamp */
    451     tmp = mr_date();
    452     log_msg(0, "Time finished: %s", tmp);
    453     mr_free(tmp);
     454    log_msg(0, "Time finished: %s", mr_date());
    454455
    455456    if (chdir("/tmp")) {
  • branches/3.1/mondo/src/mondorestore/mondo-prep.c

    r3161 r3193  
    4343extern char *MONDO_LOGFILE;
    4444
     45// FIXME: is it really usefull - maps to /tmp/prep.sh ??
    4546FILE *g_fprep = NULL;
    4647extern char *g_mondo_cfg_file;  // where m*ndo-restore.cfg (the config file) is stored
     
    108109            sync();
    109110            sync();
    110             popup_and_OK
    111                 ("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine.");
     111            popup_and_OK("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine.");
    112112            paranoid_system("reboot");
    113113        }
    114114    }
    115 // Still here? Cool!
     115    // Still here? Cool!
    116116    log_msg(1, "Cool. I didn't have to wipe anything.");
    117117}
     
    218218    }
    219219
     220    // TODO: FIXME
    220221    command = malloc(1024);
    221222
     
    390391        }
    391392        mr_asprintf(tmp1, "echo \"%s\" >> /tmp/out.sh", command);
    392         if (system(tmp1)) {
    393             //FIXME
    394         }
     393        paranoid_system(tmp1);
    395394        mr_free(tmp1);
    396395        sleep(1);
     
    515514        }
    516515    }
    517     paranoid_free(incoming);
    518516
    519517    return (0);
     
    539537    char *level   = NULL;
    540538    char *program = NULL;
    541     char *strtmp = NULL;
    542539    char *oldmd = NULL;
    543540
    544   // leave straight away if raidlist is initial or has no entries
    545   if (!raidlist || raidlist->entries == 0) {
    546     log_msg(1, "No RAID arrays found.");
    547     return 1;
    548   } else {
    549     log_msg(1, "%d RAID arrays found.", raidlist->entries);
    550   }
    551   // find raidlist entry for requested device
    552   for (i = 0; i < raidlist->entries; i++) {
    553     if (!strcmp(raidlist->el[i].raid_device, device)) break;
    554   }
    555   // check whether RAID device was found in raidlist
    556   if (i == raidlist->entries) {
    557     log_msg(1, "RAID device %s not found in list.", device);
    558     return 1;
    559   }
    560   // create device list from normal disks followed by spare ones
    561   mr_asprintf(devices, "%s", raidlist->el[i].data_disks.el[0].device);
    562   for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
    563     mr_asprintf(strtmp, "%s", devices);
    564     mr_free(devices);
    565     mr_asprintf(devices, "%s %s", strtmp, raidlist->el[i].data_disks.el[j].device);
    566     mr_free(strtmp);
    567   }
    568   for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
    569     mr_asprintf(strtmp, "%s", devices);
    570     mr_free(devices);
    571     mr_asprintf(devices, "%s %s", strtmp, raidlist->el[i].spare_disks.el[j].device);
    572     mr_free(strtmp);
    573   }
    574   // translate RAID level
    575   if (raidlist->el[i].raid_level == -2) {
    576     mr_asprintf(level, "multipath");
    577   } else if (raidlist->el[i].raid_level == -1) {
    578     mr_asprintf(level, "linear");
    579   } else {
    580     mr_asprintf(level, "raid%d", raidlist->el[i].raid_level);
    581   }
    582   // create RAID device:
    583   // - RAID device, number of devices and devices mandatory
    584   // - parity algorithm, chunk size and spare devices optional
    585   // - faulty devices ignored
    586   // - persistent superblock always used as this is recommended
    587 
    588   mr_asprintf(program, "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d %s", raidlist->el[i].raid_device, level, raidlist->el[i].data_disks.entries, oldmd);
    589   mr_free(oldmd);
    590   if (raidlist->el[i].parity != -1) {
    591     mr_asprintf(strtmp, "%s", program);
    592     mr_free(program);
    593     switch(raidlist->el[i].parity) {
    594     case 0:
    595       mr_asprintf(program, "%s --parity=%s", strtmp, "la");
    596       break;
    597     case 1:
    598       mr_asprintf(program, "%s --parity=%s", strtmp, "ra");
    599       break;
    600     case 2:
    601       mr_asprintf(program, "%s --parity=%s", strtmp, "ls");
    602       break;
    603     case 3:
    604       mr_asprintf(program, "%s --parity=%s", strtmp, "rs");
    605       break;
    606     default:
    607       fatal_error("Unknown RAID parity algorithm.");
    608       break;
    609     }
    610     mr_free(strtmp);
    611   }
    612   if (raidlist->el[i].chunk_size != -1) {
    613     mr_asprintf(strtmp, "%s", program);
    614     mr_free(program);
    615     mr_asprintf(program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size);
    616     mr_free(strtmp);
    617   }
    618   if (raidlist->el[i].spare_disks.entries > 0) {
    619     mr_asprintf(strtmp, "%s", program);
    620     mr_free(program);
    621     mr_asprintf(program, "%s --spare-devices=%d", strtmp, raidlist->el[i].spare_disks.entries);
    622     mr_free(strtmp);
    623   }
    624   mr_asprintf(strtmp, "%s", program);
    625   mr_free(program);
    626   mr_asprintf(program, "%s %s", strtmp, devices);
    627   mr_free(strtmp);
    628   res = run_program_and_log_output(program, 1);
    629   mr_free(devices);
    630   mr_free(level);
    631   mr_free(program);
    632   return res;
     541    // leave straight away if raidlist is initial or has no entries
     542    if (!raidlist || raidlist->entries == 0) {
     543      log_msg(1, "No RAID arrays found.");
     544      return 1;
     545    } else {
     546      log_msg(1, "%d RAID arrays found.", raidlist->entries);
     547    }
     548    // find raidlist entry for requested device
     549    for (i = 0; i < raidlist->entries; i++) {
     550      if (!strcmp(raidlist->el[i].raid_device, device)) break;
     551    }
     552    // check whether RAID device was found in raidlist
     553    if (i == raidlist->entries) {
     554      log_msg(1, "RAID device %s not found in list.", device);
     555      return 1;
     556    } else {
     557      log_msg(1, "RAID device %s found in list (%d).", device, i);
     558    }
     559
     560    // create device list from normal disks followed by spare ones
     561    if (raidlist->el[i].data_disks.el[0].device != NULL) {
     562        mr_asprintf(devices, "%s", raidlist->el[i].data_disks.el[0].device);
     563        log_msg(4, "Adding device %s to list", raidlist->el[i].data_disks.el[0].device);
     564    } else {
     565        log_msg(1, "Strange, there are entries but no device");
     566    }
     567    for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
     568      mr_strcat(devices, " %s", raidlist->el[i].data_disks.el[j].device);
     569      log_msg(4, "Adding device %s to list", raidlist->el[i].data_disks.el[j].device);
     570    }
     571    for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
     572      mr_strcat(devices, " %s", raidlist->el[i].spare_disks.el[j].device);
     573      log_msg(4, "Adding spare device %s to list", raidlist->el[i].spare_disks.el[j].device);
     574    }
     575    log_msg(4, "RAID devices: %s", devices);
     576    // translate RAID level
     577    if (raidlist->el[i].raid_level == -2) {
     578      mr_asprintf(level, "multipath");
     579    } else if (raidlist->el[i].raid_level == -1) {
     580      mr_asprintf(level, "linear");
     581    } else {
     582      mr_asprintf(level, "raid%d", raidlist->el[i].raid_level);
     583    }
     584    // create RAID device:
     585    // - RAID device, number of devices and devices mandatory
     586    // - parity algorithm, chunk size and spare devices optional
     587    // - faulty devices ignored
     588    // - persistent superblock always used as this is recommended
     589
     590    mr_asprintf(program, "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d", raidlist->el[i].raid_device, level, raidlist->el[i].data_disks.entries);
     591    mr_free(level);
     592    log_msg(4, "cmd built: %s", program);
     593    // Restoring the UUID and Version stored at backup time of present
     594    for (v = 0; v < raidlist->el[i].additional_vars.entries ; v++ ) {
     595        log_msg(4,"Working on additional param #%d (Label: %s)",v,raidlist->el[i].additional_vars.el[v].label);
     596        if ((raidlist->el[i].additional_vars.el[v].label != NULL) && (strcmp(raidlist->el[i].additional_vars.el[v].label,"UUID") == 0)) {
     597            // We have a UUID to handle
     598            if (raidlist->el[i].additional_vars.el[v].value != NULL) {
     599                // force its restoration in order to avoid modifying all conf files using it
     600                log_it("Managing previous UUID %s", raidlist->el[i].additional_vars.el[v].value);
     601                mr_strcat(program, " --uuid %s",raidlist->el[i].additional_vars.el[v].value);
     602                continue;
     603            } else {
     604                log_msg(1,"Unable to manage previous NULL UUID");
     605            }
     606        }
     607        if ((raidlist->el[i].additional_vars.el[v].label != NULL) && (strcmp(raidlist->el[i].additional_vars.el[v].label,"Version") == 0)) {
     608            // We have a Version to handle
     609            if (raidlist->el[i].additional_vars.el[v].value != NULL) {
     610                // force its restoration in order to support all complex boot loader + md format cases
     611                // Also see bug #473
     612                log_it("Managing previous Version %s", raidlist->el[i].additional_vars.el[v].value);
     613                mr_strcat(program, " -e %s",raidlist->el[i].additional_vars.el[v].value);
     614                continue;
     615            } else {
     616                log_msg(1,"Unable to manage previous NULL Version");
     617            }
     618        }
     619    }
     620        log_msg(4, "cmd built: %s", program);
     621    if (raidlist->el[i].parity != -1) {
     622      switch(raidlist->el[i].parity) {
     623      case 0:
     624        mr_strcat(program, " --parity=%s", "la");
     625        break;
     626      case 1:
     627        mr_strcat(program, " --parity=%s", "ra");
     628        break;
     629      case 2:
     630        mr_strcat(program, " --parity=%s", "ls");
     631        break;
     632      case 3:
     633        mr_strcat(program, " --parity=%s", "rs");
     634        break;
     635      default:
     636        fatal_error("Unknown RAID parity algorithm.");
     637        break;
     638      }
     639    }
     640    log_msg(4, "cmd built: %s", program);
     641    if (raidlist->el[i].chunk_size != -1) {
     642        mr_strcat(program, " --chunk=%d", raidlist->el[i].chunk_size);
     643    }
     644    if (raidlist->el[i].spare_disks.entries > 0) {
     645        mr_strcat(program, " --spare-devices=%d", raidlist->el[i].spare_disks.entries);
     646    }
     647    log_msg(4, "cmd built: %s", program);
     648    mr_strcat(program, " %s", devices);
     649    log_msg(2, "RAID device re-created with the following command:\n%s\n", program);
     650    if (test == TRUE) {
     651        res = run_program_and_log_output(program, 1);
     652    } else {
     653        // test mode, always returns TRUE without executing the mdadm command
     654        res = TRUE;
     655    }
     656    // free memory
     657    mr_free(devices);
     658    mr_free(program);
     659    return res;
    633660}
    634661
     
    759786        sync();
    760787        sleep(1);
     788        if (g_fprep) {
     789            fprintf(g_fprep, "%s\n", program);
     790        }
    761791
    762792        log_msg(1, "Making %s", device);
     
    845875    return (retval);
    846876}
    847 
    848 
    849 
    850877
    851878
     
    10061033    if (g_partition_table_locked_up > 0) {
    10071034        if (retval > 0 && !interactively) {
    1008 //123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
     1035                //123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
    10091036            log_to_screen("Partition table locked up %d times. At least one 'mkfs' (format) command", g_partition_table_locked_up);
    10101037            log_to_screen("failed. I think these two events are related. Sometimes, fdisk's ioctl() call");
     
    10151042                sync();
    10161043                sync();
    1017                 if (system("reboot")) {
    1018                     // FIXME
    1019                 }
     1044                paranoid_system("reboot");
    10201045            }
    10211046        } else {
     
    15581583
    15591584    if (pout_to_fdisk) {
    1560         // mark relevant partition as bootable
    1561         tmp1 = call_program_and_get_last_line_of_output ("make-me-bootable "MINDI_CACHE"/mountlist.txt dummy",TRUE);
    1562         mr_asprintf(tmp, "a\n%s\n", tmp1);
    1563         mr_free(tmp1);
    1564 
    1565         fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    1566         mr_free(tmp);
    1567 
    15681585        // close fdisk
     1586        fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
    15691587        fput_string_one_char_at_a_time(pout_to_fdisk, "w\n");
    1570         sync();
    15711588        paranoid_pclose(pout_to_fdisk);
    15721589        sync();
    15731590        log_msg(0,"------------------- fdisk.log looks like this ------------------");
    15741591        mr_asprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
    1575         if (system(tmp)) {
    1576             // FIXME
    1577         }
     1592        paranoid_system(tmp);
    15781593        mr_free(tmp);
    15791594
    1580         log_msg(0,
    1581                 "------------------- end of fdisk.log... word! ------------------");
     1595        // mark relevant partition as bootable
     1596        mr_asprintf(tmp1,"make-me-bootable /tmp/mountlist.txt %s",drivename);
     1597        call_program_and_get_last_line_of_output(tmp1);
     1598        mr_free(tmp1);
     1599        log_msg(0,"------------------- end of fdisk.log...       ------------------");
     1600        sync();
     1601
    15821602        mr_asprintf(tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG);
    15831603        if (!run_program_and_log_output(tmp, 5)) {
     
    19471967#endif
    19481968    }
    1949     log_msg(1, tmp, "Setting %s's type to %s (%s)", partition, format, partcode);
     1969    log_msg(1, "Setting %s's type to %s (%s)", partition, format, partcode);
    19501970    mr_free(partition);
    19511971
     
    20092029        }
    20102030    }
    2011 
    20122031    mr_free(partcode);
     2032
    20132033    return (res);
    20142034}
     
    20802100    mr_asprintf(program, "vinum stop -f %s", raid_device);
    20812101#else
    2082         // use raidstop if it exists, otherwise use mdadm
    2083         if (run_program_and_log_output("which raidstop", FALSE)) {
     2102    // use raidstop if it exists, otherwise use mdadm
     2103    if (run_program_and_log_output("which raidstop", FALSE)) {
    20842104        mr_asprintf(program, "mdadm -S %s", raid_device);
    20852105    } else {
     
    22012221 * @return 0 for success, nonzero for failure.
    22022222 */
    2203 char *which_format_command_do_i_need(char *format)
     2223static char *which_format_command_do_i_need(char *format)
    22042224{
    22052225    /** buffers *********************************************************/
     
    22292249    } else if (strcmp(format, "ext4") == 0) {
    22302250        mr_asprintf(program, "mkfs -t ext4 -F -q");
    2231     } else if (strcmp(format, "btrfs") == 0) {
    2232               strcpy(program, "mkfs.btrfs");
    22332251    } else if (strcmp(format, "btrfs") == 0) {
    22342252              strcpy(program, "mkfs.btrfs");
  • branches/3.1/mondo/src/mondorestore/mondo-rstr-compare.c

    r3161 r3193  
    7676    paranoid_fclose(fin);
    7777
     78
     79    mr_asprintf(bigfile_fname, "%s", biggiestruct.filename);
     80    log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);
    7881    mr_asprintf(checksum, "%s", biggiestruct.checksum);
    79     mr_asprintf(bigfile_fname, "%s", biggiestruct.filename);
    80 
    81     log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);
    8282    log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum);
    8383
     
    8585        mr_asprintf(tmp, "Comparing %s", bigfile_fname);
    8686        newtDrawRootText(0, 22, tmp);
    87         paranoid_free(tmp);
     87        mr_free(tmp);
    8888        newtRefresh();
    8989    }
    90     if (!checksum[0]) {
     90    if (checksum == NULL]) {
    9191        log_msg(2, "Warning - %s has no checksum", bigfile_fname);
    9292    }
    9393    if (!strncmp(bigfile_fname, "/dev/", 5)) {
    9494        log_msg(2, "IGNORING %s as begining with /dev", bigfile_fname);
     95        mr_free(checksum);
    9596        mr_free(bigfile_fname);
    9697        return (1);
     
    104105    mr_asprintf(tmp, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE);
    105106    paranoid_system(tmp);
    106     paranoid_free(tmp);
     107    mr_free(tmp);
    107108
    108109    if (i) {
    109110        log_OS_error("Warning - command failed");
     111        mr_free(checksum);
     112        mr_free(bigfile_fname);
    110113        return (1);
    111114    } else {
    112115        if (!(fin = fopen("/tmp/md5sum.txt", "r"))) {
    113             log_msg(2,
    114                     "Unable to open /tmp/md5sum.txt; can't get live checksum");
     116            log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum");
     117            mr_free(checksum);
    115118            mr_free(bigfile_fname);
    116119            return (1);
     
    135138
    136139    log_msg(1, tmp);
    137     paranoid_free(tmp);
     140    mr_free(tmp);
    138141
    139142    if (retval) {
     
    270273        } else {
    271274            // afio
     275            mr_asprintf(tmp, "%s", compressor_exe);
    272276            mr_free(compressor_exe);
    273             mr_asprintf(tmp, "%s", compressor_exe);
    274277            mr_asprintf(compressor_exe, "-P %s -Z", tmp);
    275278            mr_free(tmp);
     
    291294    }
    292295    mr_free(compressor_exe);
    293     paranoid_free(archiver_exe);
     296    mr_free(archiver_exe);
    294297
    295298#undef BUFSIZE
     
    474477    noof_changed_files = count_lines_in_file(MONDO_CACHE"/changed.txt");
    475478    if (noof_changed_files) {
    476         mr_asprintf(tmp, "%ld files do not match the backup            ", noof_changed_files);
    477         log_to_screen(tmp);
    478         mr_free(tmp);
     479        log_to_screen("%ld files do not match the backup            ", noof_changed_files);
    479480
    480481        mr_asprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE);
     
    525526
    526527  /**************************************************************************
    527    * also deletes tmp/filelist.full & biggielist.txt _and_ tries to     *
     528   * also deletes tmp/filelist.full & tmp/biggielist.txt _and_ tries to     *
    528529   * restore them from start of tape, if available                          *
    529530   **************************************************************************/
     
    653654    }
    654655
    655     mvaddstr_and_log_it(g_currentY,
    656                         0, "Verifying archives against filesystem");
     656    mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem");
    657657
    658658    mr_free(bkpinfo->media_device);
     
    711711    }
    712712
    713     mvaddstr_and_log_it(g_currentY,
    714                         0, "Verifying archives against filesystem");
     713    mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem");
    715714    res = verify_tape_backups();
    716715    if (chdir(dir)) {
  • branches/3.1/mondo/src/mondorestore/mondo-rstr-newt.c

    r3161 r3193  
    212212        mr_strip_spaces(size_str);
    213213
    214         strip_spaces(device_str);
     214        mr_strip_spaces(device_str);
    215215        if (b_res == bOK) {
    216216            if (device_str[strlen(device_str) - 1] == '/') {
     
    480480            mr_free(tmp);
    481481            mr_free(prompt);
    482             mr_free(prompt);
    483482            return;
    484483        }
     
    530529
    531530    assert(raidrec != NULL);
    532 
    533     if (system("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null")) {
    534         // FIXME
    535     }
     531    paranoid_system("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null");
    536532    personalities = last_line_of_file("/tmp/raid-personalities.txt");
    537533    mr_asprintf(prompt, "Please enter the RAID level you want. %s", personalities);
     
    583579    mr_free(tmp);
    584580    mr_free(prompt);
     581
    585582    raidrec->raid_level = out;
    586583#endif
     
    607604    int pos = 0;
    608605
    609     /** buffers ***********************************************************/
    610606    assert(mountlist != NULL);
    611607    assert(raidlist != NULL);
     
    931927                strcpy(g_strings_of_flist_window[i - 1], tmp1);
    932928                mr_free(tmp1);
     929
    933930                dummybool = g_is_path_selected[i];
    934931                g_is_path_selected[i] = g_is_path_selected[i - 1];
     
    16831680
    16841681    /** buffers ***********************************************************/
    1685     char title_of_editraidForm_window[MAX_STR_LEN];
     1682    char *title_of_editraidForm_window = NULL;
    16861683
    16871684    /** newt **************************************************************/
     
    17131710    memcpy((void *) &bkp_raidrec, (void *) raidrec,
    17141711           sizeof(struct vinum_plex));
    1715     sprintf(title_of_editraidForm_window, "%s.p%i",
    1716             raidlist->el[currline].volname, currline2);
     1712    mr_asprintf(title_of_editraidForm_window, "%s.p%i", raidlist->el[currline].volname, currline2);
    17171713    newtPushHelpLine
    17181714        ("   Please select a subdisk to edit, or edit this plex's parameters");
    17191715    newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window);
     1716    mr_free(title_of_editraidForm_window);
     1717
    17201718    for (;;) {
    17211719        int i;
     
    18881886        strcpy(raidrec->additional_vars.el[lino].value, p);
    18891887    }
     1888    mr_free(header);
     1889    mr_free(comment);
    18901890    mr_free(p);
    18911891}
     
    19531953    mr_asprintf(tmp, "%-24s %-24s %-8s  %s", "Device", "Mountpoint", "Format", "Size (MB)");
    19541954    headerMsg = newtLabel(2, 1, tmp);
     1955    mr_free(tmp);
     1956
    19551957    flawsLabelA = newtLabel(2, 13, "         ");
    19561958    flawsLabelB = newtLabel(2, 14, "         ");
     
    20442046    }
    20452047    newtFormDestroy(myForm);
    2046 
    2047     mr_free(flaws_str_A);
    2048     mr_free(flaws_str_B);
    2049     mr_free(flaws_str_C);
    2050     mr_free(tmp);
    2051 
    20522048    newtPopWindow();
    20532049    newtPopHelpLine();
     
    28292825                        disklist->el[currline].index = atoi(sz_res);
    28302826                    }
     2827
    28312828                    redraw_disklist(disklist, keylist, partitionsListbox);
    28322829                    mr_free(sz_res);
  • branches/3.1/mondo/src/mondorestore/mondo-rstr-tools.c

    r3161 r3193  
    9090    fatal_error("Cannot openin outfname");
    9191}
    92 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
     92for (mr_getline(incoming, fin); !feof(fin) && (incoming != NULL); mr_getline(incoming, fin)) {
    9393    mr_strip_spaces(incoming);
    9494
     
    140140}
    141141if (file[0] == '/' && file[1] == '/') {
    142     mr_asprintf(tmp, "%s", file);
    143     mr_free(file);
     142    tmp = file;
    144143
    145144    mr_asprintf(file, "%s", tmp + 1);
     
    174173* @return 0 for success, nonzero for failure.
    175174*/
    176 int iso_fiddly_bits(bool nuke_me_please)
    177 {
    178     char *mount_isodir_command = NULL;
    179     char *command = NULL;
    180     char *mds = NULL;
    181     int retval = 0, i;
    182     char *isodir_format = NULL;
     175int iso_fiddly_bits(bool nuke_me_please) {
     176
     177char *mount_isodir_command = NULL;
     178char *command = NULL;
     179char *mds = NULL;
     180int retval = 0, i;
     181char *isodir_format = NULL;
    183182
    184183g_ISO_restore_mode = TRUE;
     
    305304            mr_strcat(additional_parameters, "-o ro");
    306305        }
     306        mr_free(tmp);
     307
    307308        tmp = find_home_of_exe("setfattr");
    308309        if (tmp) {
     
    374375mr_free(mountpoint);
    375376
    376     return (res);
     377return (res);
    377378}
    378379/**************************************************************************
     
    418419            mr_free(tmp);
    419420            res = mount_device(mountlist->el[lino].device, mountlist->el[lino].mountpoint, mountlist->el[lino].format, writeable);
    420 
    421421            retval += res;
    422422            if (res) {
     
    660660assert(bkpinfo != NULL);
    661661assert(cfgf != NULL);
     662log_it("Entering read_cfg_file_into_bkpinfo");
    662663
    663664media_specified_by_user = bkpinfo->backup_media_type;   // or 'none', if not specified
     
    676677        bkpinfo->please_dont_eject = TRUE;
    677678    } else if (!strcmp(value, "iso")) {
    678         // Patch by Conor Daly - 2004/07/12
    679679        bkpinfo->backup_media_type = iso;
    680680        if (am_I_in_disaster_recovery_mode()) {
     
    687687                bkpinfo->backup_media_type = cdr;
    688688                run_program_and_log_output("umount -d "MNT_CDROM, 1);
    689                 log_it
    690                     ("Re-jigging configuration AGAIN. CD-R, not ISO.");
     689                log_it("Re-jigging configuration AGAIN. CD-R, not ISO.");
    691690            }
    692691        }
     
    698697            mr_asprintf(bkpinfo->prefix, "%s", STD_PREFIX);
    699698        }
     699        log_it("Setting Prefix to %s", bkpinfo->prefix);
    700700    } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) {
    701701        /* Stay compatible with previous versions by allowing nfs as an entry here */
     
    727727        tmp = call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE);
    728728        if (strstr(tmp, "pxe")) {
    729             /* We need to override prefix value in PXE mode as it's 
     729            /* We need to override prefix value in PXE mode as it's
    730730            * already done in start-netfs */
    731731            envtmp1 = getenv("imgname");
     
    754754        mr_free(bkpinfo->media_device);
    755755        mr_asprintf(bkpinfo->media_device, "/dev/cdrom");
    756         bkpinfo->media_size[0] = 1999 * 1024;
    757         bkpinfo->media_size[1] = 650;   /* good guess */
     756        bkpinfo->media_size = 650;  /* good guess */
    758757    } else if (bkpinfo->backup_media_type == usb) {
    759758        envtmp1 = getenv("MRUSBDEV");
     
    778777        value = read_cfg_var(cfg_file, "media-size");
    779778        if (value != NULL) {
    780             bkpinfo->media_size[1] = atol(value);
     779            bkpinfo->media_size = atol(value);
    781780            mr_free(value);
    782781        } else {
    783             bkpinfo->media_size[1] = 0L;
     782            bkpinfo->media_size = 0L;
    784783        }
    785784        log_msg(2, "Backup medium is TAPE --- dev=%s", bkpinfo->media_device);
     
    787786        mr_free(bkpinfo->media_device);
    788787        mr_asprintf(bkpinfo->media_device, "/dev/cdrom");   /* we don't really need this var */
    789         bkpinfo->media_size[0] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
    790         bkpinfo->media_size[1] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
    791         log_msg(2, "Backup medium is CD-R[W]");
     788        bkpinfo->media_size = 1999 * 1024;  /* 650, probably, but we don't need this var anyway */
     789        log_msg(2, "Backup medium is similar to CD-R[W]");
    792790    }
    793791} else {
     
    968966        mr_free(tmp1);
    969967    }
    970 
    971968} else if (bkpinfo->backup_media_type == iso) {
    972969    /* Patch by Conor Daly 23-june-2004
     
    10441041    if (! bkpinfo->disaster_recovery) {
    10451042        if (bkpinfo->backup_media_type != media_specified_by_user) {
    1046             log_msg(2,
    1047                     "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
     1043            log_msg(2, "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
    10481044            interactively_obtain_media_parameters_from_user(FALSE);
    10491045            media_specified_by_user = bkpinfo->backup_media_type;
     
    10861082int res = 0;
    10871083pid_t pid;
     1084bool extract_mountlist_stub = FALSE;
    10881085
    10891086assert(bkpinfo != NULL);
     
    12341231            popup_and_OK("You'll now be chrooted under your future / partition.\nEdit /etc/mkinitcpio.conf if needed and rebuild your initrd with the kernel preset name e.g.\nmkinitcpio -p kernel26\nThen type exit to finish.\n");
    12351232        } else {
    1236             popup_and_OK("You'll now be chrooted under your future / partition.\nGo under /boot and rebuild your initrd with\nmkinitrd -f -v initrd-2.x.y.img 2.x.y e.g.\nThen type exit to finish.");
     1233            popup_and_OK("You'll now be chrooted under your future / partition.\nGo under /boot and rebuild your init(rd|ramfs) with\nmkinitrd -f -v initrd-2.x.y.img 2.x.y e.g.\nor initramfs, dracut, ... Then type exit to finish.");
    12371234        }
    12381235        mvaddstr_and_log_it(g_currentY, 0, "Modifying initrd...");
     
    14351432
    14361433            if ((res) || (mntlistchg)) {
    1437                 popup_and_OK("GRUB installation failed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
    1438             } else {
    1439                 popup_and_OK("The mountlist was changed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
    1440             }
    1441             if (!g_text_mode) {
    1442                 newtSuspend();
    1443             }
    1444             mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
    1445             paranoid_system(tmp);
    1446             mr_free(tmp);
    1447 
    1448             mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
    1449             paranoid_system(tmp);
    1450             mr_free(tmp);
    1451 
    1452             if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) {
    1453                 mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
    1454             } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) {
    1455                 mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
    1456             } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) {
    1457                 mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);
    1458             }
    1459             paranoid_system(tmp);
    1460             mr_free(tmp);
    1461 
    1462             if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) {
     1434                if (res) {
     1435                    popup_and_OK("GRUB installation failed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
     1436                } else {
     1437                    popup_and_OK("The mountlist was changed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
     1438                }
     1439                if (!g_text_mode) {
     1440                    newtSuspend();
     1441                }
     1442                mr_asprintf(editor, "%s", find_my_editor());
     1443                mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
     1444                paranoid_system(tmp);
     1445                mr_free(tmp);
     1446
     1447                mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
     1448                paranoid_system(tmp);
     1449                mr_free(tmp);
     1450   
     1451                if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) {
     1452                    mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
     1453                } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) {
     1454                    mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
     1455                } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) {
     1456                    mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);
     1457                }
     1458                paranoid_system(tmp);
     1459                mr_free(tmp);
     1460   
     1461                if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) {
     1462                    mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
     1463                } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) {
     1464                    mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);
     1465                }
     1466                paranoid_system(tmp);
     1467                mr_free(tmp);
     1468
     1469                if (!g_text_mode) {
     1470                    newtResume();
     1471                }
     1472                mr_asprintf(command, "stabgrub-me %s", boot_device);
     1473                res = run_program_and_log_output(command, 1);
     1474                mr_free(command);
     1475
     1476                if (res) {
     1477                    popup_and_OK("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
     1478                    newtSuspend();
     1479                    paranoid_system("chroot " MNT_RESTORING);
     1480                    newtResume();
     1481                    popup_and_OK("Thank you.");
     1482                } else {
     1483                    popup_and_OK("GRUB is now installed correctly");
     1484                    done = TRUE;
     1485                }
     1486                popup_and_OK("You will now edit fstab, mtab, device.map and menu.lst/grub.cfg");
     1487                if (!g_text_mode) {
     1488                    newtSuspend();
     1489                }
     1490   
     1491                mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
     1492                paranoid_system(tmp);
     1493                mr_free(tmp);
     1494   
     1495                mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
     1496                paranoid_system(tmp);
     1497                mr_free(tmp);
     1498   
     1499                if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) {
     1500                    mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
     1501                } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) {
     1502                    mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
     1503                }
     1504                paranoid_system(tmp);
     1505                mr_free(tmp);
     1506
    14631507                mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
    1464             } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) {
    1465                 mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);
    1466             }
    1467             paranoid_system(tmp);
    1468             mr_free(tmp);
    1469 
    1470             if (!g_text_mode) {
    1471                 newtResume();
    1472             }
    1473             mr_asprintf(command, "stabgrub-me %s", boot_device);
    1474             res = run_program_and_log_output(command, 1);
    1475             mr_free(command);
    1476             if (res) {
    1477                 popup_and_OK("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
    1478                 newtSuspend();
    1479                 paranoid_system("chroot " MNT_RESTORING);
    1480                 newtResume();
    1481                 popup_and_OK("Thank you.");
    1482             } else {
    1483                 popup_and_OK("GRUB is now installed correctly");
    1484                 done = TRUE;
    1485             }
    1486             popup_and_OK("You will now edit fstab, mtab, device.map and menu.lst/grub.cfg");
    1487             if (!g_text_mode) {
    1488                 newtSuspend();
    1489             }
    1490             mr_asprintf(editor, "%s", find_my_editor());
    1491 
    1492             mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
    1493             paranoid_system(tmp);
    1494             mr_free(tmp);
    1495 
    1496             mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
    1497             paranoid_system(tmp);
    1498             mr_free(tmp);
    1499 
    1500             if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) {
    1501                 mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
    1502             } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) {
    1503                 mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
    1504             }
    1505             paranoid_system(tmp);
    1506             mr_free(tmp);
    1507 
    1508             mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
    1509             paranoid_system(tmp);
    1510             mr_free(tmp);
    1511             mr_free(editor);
    1512 
    1513             if (!g_text_mode) {
    1514                 newtResume();
     1508                paranoid_system(tmp);
     1509                mr_free(tmp);
     1510                mr_free(editor);
     1511   
     1512                if (!g_text_mode) {
     1513                    newtResume();
     1514                }
    15151515            }
    15161516        }
     
    15251525            log_msg(1, "WARNING - grub-MR not found; using grub-install");
    15261526        }
    1527         mvaddstr_and_log_it(g_currentY,
    1528                             0,
    1529                             "Running GRUB...                                                 ");
     1527        mvaddstr_and_log_it(g_currentY, 0, "Running GRUB...                                                 ");
    15301528        log_it("%s",command);
    15311529        res = run_program_and_log_output(command, 1);
     
    16111609                paranoid_system(tmp);
    16121610                mr_free(tmp);
    1613 
    16141611                mr_free(editor);
    16151612
     
    16881685                paranoid_system(tmp);
    16891686                mr_free(tmp);
    1690 
    16911687                mr_free(editor);
    16921688
     
    21142110    paranoid_free(raidlist);
    21152111}
    2116 
    2117 
  • branches/3.1/mondo/src/mondorestore/mondoprep.h

    r3147 r3193  
    6969int partition_everything(struct mountlist_itself *);
    7070int do_my_funky_lvm_stuff(bool, bool);
    71 char *which_format_command_do_i_need(char *);
    7271int make_dummy_partitions(FILE *, char *, int);
    7372int make_list_of_drives(struct mountlist_itself *,
  • branches/3.1/mondo/src/mondorestore/mondorestore.c

    r3161 r3193  
    582582                    log_msg(1, "Restoring subset");
    583583                    retval += restore_everything(filelist);
     584                    free_filelist(filelist);
    584585                } else {
    585586                    mr_free(bkpinfo->restore_path);
     
    839840                        "Using tune2fs/tune4fs to identify your ext2,3,4 partitions");
    840841
    841     mr_asprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", MINDI_CACHE"/mountlist.txt", MONDO_LOGFILE, MONDO_LOGFILE);
     842    mr_asprintf(tmp1, "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", MINDI_CACHE"/mountlist.txt", MONDO_LOGFILE, MONDO_LOGFILE);
    842843    res = run_program_and_log_output(tmp, TRUE);
    843     mr_free(tmp);
     844    mr_free(tmp1);
    844845    if (res) {
    845846        log_to_screen("label-partitions-as-necessary returned an error");
     
    20452046    int res;
    20462047    int attempts;
    2047     long current_tarball_number = 0;
     2048    long current_tarball_number = 0L;
    20482049    long max_val;
    20492050  /**malloc ***/
     
    26202621    mr_free(tmp1);
    26212622
     2623    mountlist = (struct mountlist_itself *)mr_malloc(sizeof(struct mountlist_itself));
     2624    raidlist = (struct raidlist_itself *)mr_malloc(sizeof(struct raidlist_itself));
     2625
     2626
     2627
    26222628    /* Init GUI */
    26232629    setup_newt_stuff();         /* call newtInit and setup screen log */
     
    26662672
    26672673    log_it("what time is it");
    2668 
    2669     mountlist = (struct mountlist_itself *)mr_malloc(sizeof(struct mountlist_itself));
    2670     raidlist = (struct raidlist_itself *)mr_malloc(sizeof(struct raidlist_itself));
    26712674
    26722675    /* Process command-line parameters */
     
    27992802        mount_boot_if_necessary();  /* for Gentoo users */
    28002803        log_msg(2, "Still here.");
    2801         /* Adding an initialisation in order to avoid to hndle NULL pointer later */
     2804        /* Adding an initialisation in order to avoid to handle NULL pointer later */
    28022805        mr_free(bkpinfo->restore_path);
    28032806        mr_asprintf(bkpinfo->restore_path, "%s", "/tmp");
  • branches/3.2/mondo/src/include/mr_str.h

    r3171 r3193  
    1919extern inline char *mr_date(void);
    2020extern void mr_strip_spaces(char *in_out);
     21/*
     22extern void mr_strip_char(char *in_out, char *caracs);
     23extern void mr_chomp(char *in_out);
     24*/
    2125
    2226#endif                          /* MR_STR_H */
  • branches/3.2/mondo/src/include/my-stuff.h

    r3191 r3193  
    88// Extra info for ACLs and SELINUX users
    99#define STAR_ACL_SZ "-xattr -acl"
    10 //#define STAR_ACL_SZ "-xfflags"
    11 //#define STAR_ACL_SZ ""
    12 // Enable the first line and disable the second if you are a Fedora Core 2 user
    1310
    1411/**
     
    230227 */
    231228#define MAX_TAPECAT_FNAME_LEN 32
    232 
    233 //#define strcpy(y,x) strncpy(y, x, sizeof(y)-1)
    234 
    235229
    236230/**
     
    346340#define ARCH_BUFFER_NUM (ARCH_THREADS*4)    // Number of permissible queued afio files
    347341#define FORTY_SPACES "                                         "    ///< 40 spaces.
    348     ///< Size of the tmpfs, in megabytes, to attempt to mount (to speed up Mondo).
    349 /*
    350 #define PPCFG_RAMDISK_SIZE 350
    351 */
    352 
    353342#define DO_MBR_PLEASE "/tmp/DO-MBR-PLEASE"
    354343#define MONDO_MNTLISTCHG "/tmp/mountlist.changed"
  • branches/3.2/mondo/src/lib/mr_str.c

    r3171 r3193  
    146146}
    147147
     148/* Return an allocated string containing the date
     149char *mr_date(void) {
     150   
     151    time_t tcurr;
     152    char *tmp = NULL;
     153
     154    tcurr = time(NULL);
     155    mr_asprintf(tmp, "%s", ctime(&tcurr));
     156    mr_chomp(tmp);
     157    return(tmp);
     158}
     159 */
    148160
    149161/**
     
    181193    in_out[i] = '\0';
    182194}
     195
     196
     197/*
     198 * Remove '\n' char from both sides of @p in_out.
     199 * @param in_out The string to strip characters from (modified).
     200
     201void mr_chomp(char *in_out) {
     202
     203    mr_strip_char(in_out, "\n");
     204}
     205*/
     206
     207/**
     208 * Remove all characters in caracs from begining and end of string @p in_out
     209 * @param in_out The string to strip char characters from (modified).
     210
     211void mr_strip_char(char *in_out, char *caracs) {
     212    int i = 0;
     213    int j = 0;
     214    size_t length = 0;
     215
     216    if (caracs == NULL) {
     217        return;
     218    }
     219    if (in_out == NULL) {
     220        return;
     221    }
     222    length = strlen(in_out);
     223
     224    /* Skip initial caracs */
     225    for (i = 0; index(caracs, in_out[i]) != NULL && i < (int)length ; i++);
     226
     227    /* Shift the string to the begining if needed */
     228    if (i != 0) {
     229        for (j = 0; i < (int)length ; i++, j++) {
     230            in_out[j] = in_out[i];
     231        }
     232        /* Erase the end of the string if needed */
     233        j++;
     234        in_out[j] = '\0';
     235    }
     236
     237    /* Skip final caracs */
     238    for (i = (int)strlen(in_out) - 1; i >= 0  && index(caracs, in_out[i]) != NULL; i--);
     239
     240    /* The string now ends after that char */
     241    i++;
     242    in_out[i] = '\0';
     243}
     244*/
     245
  • branches/3.2/mondo/src/mondoarchive/mondoarchive.c

    r3185 r3193  
    1010#include "my-stuff.h"
    1111#include "mr_mem.h"
     12#include "mr_str.h"
    1213#include "../common/mondostructures.h"
    1314#include "../common/libmondo.h"
     
    3233
    3334/***************** global vars, used only by main.c ******************/
    34 long diffs;
     35long diffs = 0L;
    3536
    3637extern t_bkptype g_backup_media_type;
    3738extern int g_loglevel;
     39
     40extern char *g_magicdev_command;
    3841
    3942/**
     
    7477    char *tmp = NULL;
    7578
    76     log_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org",
    77             PACKAGE_VERSION);
     79    log_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", PACKAGE_VERSION);
    7880    log_msg(0, "running %s binaries", get_architecture());
    7981    tmp = get_uname_m();
    8082    log_msg(0, "running on %s architecture", tmp);
    8183    mr_free(tmp);
    82     log_msg(0,
    83             "-----------------------------------------------------------");
    84     log_msg(0,
    85             "NB: Mondo logs almost everything, so don't panic if you see");
    86     log_msg(0,
    87             "some error messages.  Please read them carefully before you");
    88     log_msg(0,
    89             "decide to break out in a cold sweat.    Despite (or perhaps");
    90     log_msg(0,
    91             "because of) the wealth of messages. some users are inclined");
    92     log_msg(0,
    93             "to stop reading this log. If Mondo stopped for some reason,");
    94     log_msg(0,
    95             "chances are it's detailed here.  More than likely there's a");
    96     log_msg(0,
    97             "message at the very end of this log that will tell you what");
    98     log_msg(0,
    99             "is wrong. Please read it!                          -Devteam");
    100     log_msg(0,
    101             "-----------------------------------------------------------");
     84    log_msg(0, "-----------------------------------------------------------");
     85    log_msg(0, "NB: Mondo logs almost everything, so don't panic if you see");
     86    log_msg(0, "some error messages.  Please read them carefully before you");
     87    log_msg(0, "decide to break out in a cold sweat.    Despite (or perhaps");
     88    log_msg(0, "because of) the wealth of messages. some users are inclined");
     89    log_msg(0, "to stop reading this log. If Mondo stopped for some reason,");
     90    log_msg(0, "chances are it's detailed here.  More than likely there's a");
     91    log_msg(0, "message at the very end of this log that will tell you what");
     92    log_msg(0, "is wrong. Please read it!                          -Devteam");
     93    log_msg(0, "-----------------------------------------------------------");
    10294
    10395    log_msg(0, "Zero...");
     
    113105}
    114106
    115 
    116 extern char *g_magicdev_command;
    117107
    118108/**
     
    170160    char *tmp = NULL;
    171161    char *tmp1 = NULL;
    172     int res, retval;
     162    int res = 0;
     163    int i = 0;
     164    int retval = 0;
    173165    char *say_at_end = NULL;
    174166    FILE *fin = NULL;
     
    181173
    182174/* If -V, -v or --version then echo version no. and quit */
    183     if (argc == 2
    184         && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
    185             || !strcmp(argv[argc - 1], "--version"))) {
     175    if (argc == 2 && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V") || !strcmp(argv[argc - 1], "--version"))) {
    186176        printf("mondoarchive v%s\nSee man page for help\n", PACKAGE_VERSION);
    187177        exit(0);
     
    196186    reset_bkpinfo();
    197187
    198     res = 0;
    199     retval = 0;
    200     diffs = 0;
     188    /* Memory allocation is done in those functions */
    201189    malloc_libmondo_global_strings();
    202190
     
    208196    mr_asprintf(tmp1,"%s:/sbin:/usr/sbin:/usr/local/sbin",getenv("PATH"));
    209197    setenv("PATH", tmp1, 1);
    210     paranoid_free(tmp1);
     198    mr_free(tmp1);
    211199
    212200    /* Add the ARCH environment variable for ia64 purposes */
    213201    mr_asprintf(tmp1,"%s",get_architecture());
    214202    setenv("ARCH", tmp1, 1);
    215     paranoid_free(tmp1);
     203    mr_free(tmp1);
    216204
    217205    /* Add MONDO_SHARE environment variable for mindi */
     
    255243        g_text_mode = TRUE;
    256244        setup_newt_stuff();
    257         malloc_string(tmp);
    258         turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
    259         printf("in=%s; out=%s\n", argv[2], tmp);
    260         paranoid_free(tmp);
     245        tmp1 = mr_stresc(argv[2], "[]*?", '\\');
     246        printf("in=%s; out=%s\n", argv[2], tmp1);
     247        mr_free(tmp1);
    261248        finish(1);
    262249    }
     
    311298            printf("CD-ROM is at %s\n", tmp);
    312299        }
    313         paranoid_free(tmp);
     300        mr_free(tmp);
    314301        finish(0);
    315302    }
     
    325312            printf("DVD is at %s\n", tmp);
    326313        }
    327         paranoid_free(tmp);
     314        mr_free(tmp);
    328315        finish(0);
    329316    }
     
    343330
    344331    if (pre_param_configuration()) {
    345         fatal_error
    346             ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
    347     }
    348 
    349 /* Process command line, if there is one. If not, ask user for info. */
     332        fatal_error("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
     333    }
     334
     335    /* Process command line, if there is one. If not, ask user for info. */
    350336    if (argc == 1) {
    351337        g_text_mode = FALSE;
     
    353339        res = interactively_obtain_media_parameters_from_user(TRUE);    /* yes, archiving */
    354340        if (res) {
    355             fatal_error
    356                 ("Syntax error. Please review the parameters you have supplied and try again.");
     341            fatal_error("Syntax error. Please review the parameters you have supplied and try again.");
    357342        }
    358343    } else {
    359344        res = handle_incoming_parameters(argc, argv);
    360345        if (res) {
    361             printf
    362                 ("Errors were detected in the command line you supplied.\n");
     346            printf("Errors were detected in the command line you supplied.\n");
    363347            printf("Please review the log file - %s\n", MONDO_LOGFILE );
    364348            log_msg(1, "Mondoarchive will now exit.");
     
    370354/* Finish configuring global structures */
    371355    if (post_param_configuration()) {
    372         fatal_error
    373             ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
    374     }
    375 
    376     log_to_screen
    377         ("BusyBox's sources are available from http://www.busybox.net");
     356        fatal_error("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
     357    }
    378358
    379359    /* If we're meant to backup then backup */
     
    392372        res = verify_data();
    393373        if (res < 0) {
    394             mr_asprintf(tmp, "%d difference%c found.", -res,
    395                     (-res != 1) ? 's' : ' ');
     374            mr_asprintf(tmp, "%d difference%c found.", -res, (-res != 1) ? 's' : ' ');
    396375            mr_asprintf(say_at_end, "%s", tmp);
    397376            log_to_screen(tmp);
     
    430409    if (say_at_end != NULL) {
    431410        log_to_screen(say_at_end);
    432         paranoid_free(say_at_end);
     411        mr_free(say_at_end);
    433412    }
    434413    mr_asprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
     
    437416    if (bkpinfo->backup_media_type == usb) {
    438417        log_msg(1, "Unmounting USB device.");
     418        if (bkpinfo->media_device == NULL) {
     419            fatal_error("USB device set to NULL");
     420        }
    439421        mr_asprintf(tmp, "umount %s1", bkpinfo->media_device);
    440422        run_program_and_log_output(tmp, TRUE);
     
    471453
    472454    if (!g_text_mode) {
    473         popup_and_OK
    474             ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt.");
     455        popup_and_OK("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt.");
    475456        log_to_screen("See %s for details of backup run.", MONDO_LOGFILE);
    476457    } else {
  • branches/3.2/mondo/src/mondoarchive/mondoarchive.h

    r3141 r3193  
    99 */
    1010char *MONDO_LOGFILE = "/var/log/mondoarchive.log";
    11 char *MONDO_OPTIONS = "0123456789A:B:C:DE:FGHI:J:K:LM:NOP:QRS:T:UVWb:c:d:ef:gik:l:mn:op:rs:tuw:x:z";
     11char *MONDO_OPTIONS = "0123456789A:B:C:DE:FGHI:J:K:LM:NOP:QRS:T:UVWYb:c:d:ef:gik:l:mn:op:rs:tuw:x:z";
    1212
    1313/* No restriction on ps options */
  • branches/3.2/mondo/src/mondorestore/mondo-rstr-compare.c

    r3185 r3193  
    4343
    4444  /** needs malloc *******/
    45     char *checksum_ptr;
    46     char *original_cksum_ptr;
    47     char *bigfile_fname_ptr;
    48     char *tmp_ptr = NULL;
    49     char *command_ptr;
    50 
    51     char *checksum, *original_cksum, *bigfile_fname, *tmp, *command;
     45    char *checksum = NULL;
     46    char *original_cksum = NULL;
     47    char *bigfile_fname = NULL;
     48    char *tmp = NULL;
     49    char *command = NULL;
    5250
    5351    char *p;
     
    5654
    5755    struct s_filename_and_lstat_info biggiestruct;
    58 
    59     malloc_string(checksum);
    60     malloc_string(original_cksum);
    61     malloc_string(bigfile_fname);
    62     malloc_string(tmp);
    63     malloc_string(command);
    64     malloc_string(checksum_ptr);
    65     malloc_string(original_cksum_ptr);
    66     malloc_string(bigfile_fname_ptr);
    67     malloc_string(command_ptr);
    6856
    6957  /*********************************************************************
     
    7159   *********************************************************************/
    7260    assert(bkpinfo != NULL);
    73     memset(checksum_ptr, '\0', sizeof(checksum));
    74     memset(original_cksum_ptr, '\0', sizeof(original_cksum));
    75     memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));
    76     memset(command_ptr, '\0', sizeof(command));
    7761  /** end **/
    7862
     
    8165            insist_on_this_cd_number((++g_current_media_number));
    8266        } else {
    83             mr_asprintf(tmp_ptr, "No CD's left. No biggiefiles left. No prob, Bob.");
    84             log_msg(2, tmp_ptr);
    85             paranoid_free(tmp_ptr);
     67            log_msg(2, "No CD's left. No biggiefiles left. No prob, Bob.");
    8668            return (0);
    8769        }
    8870    }
    8971    if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
    90         mr_asprintf(tmp_ptr, "Cannot open bigfile %ld (%s)'s info file", bigfileno + 1, bigfile_fname_ptr);
    91         log_to_screen(tmp_ptr);
    92         paranoid_free(tmp_ptr);
     72        log_to_screen("Cannot open bigfile %ld (NULL)'s info file", bigfileno + 1);
    9373        return (1);
    9474    }
     
    9878    paranoid_fclose(fin);
    9979
    100     strcpy(checksum_ptr, biggiestruct.checksum);
    101     strcpy(bigfile_fname_ptr, biggiestruct.filename);
    102 
     80
     81    mr_asprintf(bigfile_fname, "%s", biggiestruct.filename);
    10382    log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);
     83    mr_asprintf(checksum, "%s", biggiestruct.checksum);
    10484    log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum);
    10585
    10686    if (!g_text_mode) {
    107         mr_asprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr);
    108         newtDrawRootText(0, 22, tmp_ptr);
    109         paranoid_free(tmp_ptr);
     87        mr_asprintf(tmp, "Comparing %s", bigfile_fname);
     88        newtDrawRootText(0, 22, tmp);
     89        mr_free(tmp);
    11090        newtRefresh();
    11191    }
    112     if (!checksum[0]) {
    113         log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr);
    114     }
    115     if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) {
    116         strcpy(original_cksum_ptr, "IGNORE");
    117     } else {
    118         sprintf(command_ptr,
    119                 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors",
    120                 MNT_RESTORING, bigfile_fname_ptr);
    121     }
    122     log_msg(2, command_ptr);
    123     mr_asprintf(tmp_ptr, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE);
    124     paranoid_system(tmp_ptr);
    125     paranoid_free(tmp_ptr);
    126 
    127     if (system(command_ptr)) {
     92    if (checksum == NULL]) {
     93        log_msg(2, "Warning - %s has no checksum", bigfile_fname);
     94    }
     95    if (!strncmp(bigfile_fname, "/dev/", 5)) {
     96        log_msg(2, "IGNORING %s as begining with /dev", bigfile_fname);
     97        mr_free(checksum);
     98        mr_free(bigfile_fname);
     99        return (1);
     100    }
     101
     102    mr_asprintf(command, "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors", MNT_RESTORING, bigfile_fname);
     103    log_msg(2, command);
     104    i =  system(command);
     105    mr_free(command);
     106
     107    mr_asprintf(tmp, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE);
     108    paranoid_system(tmp);
     109    mr_free(tmp);
     110
     111    if (i) {
    128112        log_OS_error("Warning - command failed");
    129         original_cksum[0] = '\0';
     113        mr_free(checksum);
     114        mr_free(bigfile_fname);
    130115        return (1);
    131116    } else {
    132117        if (!(fin = fopen("/tmp/md5sum.txt", "r"))) {
    133             log_msg(2,
    134                     "Unable to open /tmp/md5sum.txt; can't get live checksum");
    135             original_cksum[0] = '\0';
     118            log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum");
     119            mr_free(checksum);
     120            mr_free(bigfile_fname);
    136121            return (1);
    137122        } else {
    138             if (fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin)) {
    139                 // FIXME
    140             }
     123            mr_getline(original_cksum, fin);
    141124            paranoid_fclose(fin);
    142             for (i = strlen(original_cksum_ptr);
     125            for (i = strlen(original_cksum);
    143126                 i > 0 && original_cksum[i - 1] < 32; i--);
    144127            original_cksum[i] = '\0';
    145             p = (char *) strchr(original_cksum_ptr, ' ');
     128            p = strchr(original_cksum, ' ');
    146129            if (p) {
    147130                *p = '\0';
     
    149132        }
    150133    }
    151     mr_asprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname_ptr);
    152     if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) {
    153         mr_strcat(tmp_ptr, " ... OK");
    154     } else {
    155         mr_strcat(tmp_ptr, "... changed");
     134    mr_asprintf(tmp, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname);
     135    if ((original_cksum != NULL) && (strcmp(checksum, original_cksum) == 0)) {
     136        mr_strcat(tmp, " ... OK");
     137    } else {
     138        mr_strcat(tmp, "... changed");
    156139        retval++;
    157140    }
    158     log_msg(1, tmp_ptr);
    159     paranoid_free(tmp_ptr);
     141    mr_free(checksum);
     142    mr_free(original_cksum);
     143
     144    log_msg(1, tmp);
     145    mr_free(tmp);
    160146
    161147    if (retval) {
     
    163149            fatal_error("Cannot openout changed.txt");
    164150        }
    165         fprintf(fout, "%s\n", bigfile_fname_ptr);
     151        fprintf(fout, "%s\n", bigfile_fname);
    166152        paranoid_fclose(fout);
    167153    }
    168 
    169     paranoid_free(original_cksum_ptr);
    170     paranoid_free(original_cksum);
    171     paranoid_free(bigfile_fname_ptr);
    172     paranoid_free(bigfile_fname);
    173     paranoid_free(checksum_ptr);
    174     paranoid_free(checksum);
    175     paranoid_free(command_ptr);
    176     paranoid_free(command);
    177     paranoid_free(tmp);
     154    mr_free(bigfile_fname);
    178155
    179156    return (retval);
     
    194171    int res;
    195172    long noof_biggiefiles, bigfileno = 0;
    196     char tmp[MAX_STR_LEN];
     173    char *tmp = NULL;
    197174
    198175    log_msg(1, "Comparing biggiefiles");
     
    215192                       noof_biggiefiles);
    216193    for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) {
    217         sprintf(tmp, "Comparing big file #%ld", bigfileno + 1);
     194        mr_asprintf(tmp, "Comparing big file #%ld", bigfileno + 1);
    218195        log_msg(1, tmp);
    219196        update_progress_form(tmp);
     197        mr_free(tmp);
     198
    220199        res = compare_a_biggiefile(bigfileno);
    221200        retval += res;
     
    253232
    254233  /***  needs malloc *********/
    255     char *command, *tmp, *filelist_name, *logfile,
    256         *compressor_exe;
     234    char *command = NULL;
     235    char *tmp = NULL;
    257236    char *archiver_exe = NULL;
    258 
    259     malloc_string(command);
    260     malloc_string(tmp);
    261     malloc_string(filelist_name);
    262     malloc_string(logfile);
    263     malloc_string(compressor_exe);
     237    char *tmp1 = NULL;
     238    char *logfile = NULL;
     239    char *compressor_exe = NULL;
    264240
    265241    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    266242    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    267     sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number);
    268     sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d",
    269             current_tarball_number);
     243    mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", current_tarball_number);
    270244
    271245    if (strstr(tarball_fname, ".bz2")) {
    272         strcpy(compressor_exe, "bzip2");
     246        mr_asprintf(compressor_exe, "bzip2");
     247    } else if (strstr(tarball_fname, ".lzma")) {
     248        mr_asprintf(compressor_exe, "lzma");
    273249    } else if (strstr(tarball_fname, ".gz")) {
    274         strcpy(compressor_exe, "gzip");
     250        mr_asprintf(compressor_exe, "gzip");
    275251    } else if (strstr(tarball_fname, ".lzo")) {
    276         strcpy(compressor_exe, "lzop");
    277     } else {
    278         compressor_exe[0] = '\0';
     252        mr_asprintf(compressor_exe, "lzop");
    279253    }
    280254
     
    285259    }
    286260
    287     if (compressor_exe[0]) {
    288         strcpy(tmp, compressor_exe);
     261    if (compressor_exe) {
     262        mr_asprintf(tmp, "%s", compressor_exe);
    289263        if (!find_home_of_exe(tmp)) {
     264            mr_free(tmp);
     265            mr_free(compressor_exe);
     266            mr_free(archiver_exe);
    290267            fatal_error("(compare_a_tarball) Compression program missing");
    291268        }
    292         if (use_star)           // star
    293         {
     269        mr_free(tmp);
     270
     271        if (use_star) {
    294272            if (!strcmp(compressor_exe, "bzip2")) {
    295273                mr_strcat(archiver_exe, " -bz");
    296274            } else {
    297                 fatal_error
    298                     ("(compare_a_tarball) Please use only bzip2 with star");
     275                mr_free(compressor_exe);
     276                mr_free(archiver_exe);
     277                fatal_error("(compare_a_tarball) Please use only bzip2 with star");
    299278            }
    300         } else                  // afio
    301         {
    302             sprintf(compressor_exe, "-P %s -Z", tmp);
    303         }
    304     }
    305 // star -diff H=star -bz file=....
     279        } else {
     280            // afio
     281            mr_asprintf(tmp, "%s", compressor_exe);
     282            mr_free(compressor_exe);
     283            mr_asprintf(compressor_exe, "-P %s -Z", tmp);
     284            mr_free(tmp);
     285        }
     286    }
    306287
    307288#ifdef __FreeBSD__
     
    310291#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
    311292#endif
    312     if (use_star)               // doesn't use compressor_exe
    313     {
    314         sprintf(command,
    315                 "%s -sparse -diff H=exustar file=%s >> %s 2>> %s",
    316                 archiver_exe, tarball_fname, logfile, logfile);
    317     } else {
    318         sprintf(command,
    319                 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s",
    320                 archiver_exe,
    321                 TAPE_BLOCK_SIZE,
    322                 BUFSIZE, compressor_exe, tarball_fname, logfile, logfile);
    323     }
    324     paranoid_free(archiver_exe);
     293    mr_asprintf(logfile, "/tmp/afio.log.%d", current_tarball_number);
     294
     295    if (use_star) {
     296        // doesn't use compressor_exe
     297        mr_asprintf(command, "%s -sparse -diff H=exustar file=%s >> %s 2>> %s", archiver_exe, tarball_fname, logfile, logfile);
     298    } else {
     299        mr_asprintf(command, "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", archiver_exe, TAPE_BLOCK_SIZE, BUFSIZE, compressor_exe, tarball_fname, logfile, logfile);
     300    }
     301    mr_free(compressor_exe);
     302    mr_free(archiver_exe);
    325303
    326304#undef BUFSIZE
     
    330308    if (res) {
    331309        log_OS_error(command);
    332         sprintf(tmp, "Warning - afio returned error = %d", res);
    333         log_msg(2, tmp);
    334     }
     310        log_msg(2, "Warning - afio returned error = %d", res);
     311    }
     312    mr_free(command);
     313
    335314    if (length_of_file(logfile) > 5) {
    336         sprintf(command,
    337                 "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt",
    338                 logfile);
     315        mr_asprintf(command, "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt", logfile);
    339316        paranoid_system(command);
     317        mr_free(command);
     318
    340319        archiver_errors = count_lines_in_file(logfile);
    341320    } else {
    342321        archiver_errors = 0;
    343322    }
    344     sprintf(tmp, "%ld difference%c in fileset #%d          ",
    345             archiver_errors, (archiver_errors != 1) ? 's' : ' ',
    346             current_tarball_number);
    347323    if (archiver_errors) {
    348         sprintf(tmp,
    349                 "Differences found while processing fileset #%d       ",
    350                 current_tarball_number);
    351         log_msg(1, tmp);
     324        log_msg(1, "%ld difference%c in fileset #%d          ", archiver_errors, (archiver_errors != 1) ? 's' : ' ', current_tarball_number);
    352325    }
    353326    unlink(logfile);
    354     paranoid_free(command);
    355     paranoid_free(tmp);
    356     paranoid_free(filelist_name);
    357     paranoid_free(logfile);
    358     paranoid_free(compressor_exe);
     327    mr_free(logfile);
     328
    359329    return (retval);
    360330}
     
    377347  /**  needs malloc **********/
    378348
    379     char *tarball_fname, *progress_str, *tmp;
     349    char *tarball_fname = NULL;
     350    char *progress_str = NULL;
     351    char *tmp = NULL;
    380352    char *mds = NULL;
    381353    long max_val;
    382354
    383     malloc_string(tarball_fname);
    384     malloc_string(progress_str);
    385355    malloc_string(tmp);
    386 
    387356    assert(bkpinfo != NULL);
    388357    mvaddstr_and_log_it(g_currentY, 0, "Comparing archives");
    389358    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
    390 
    391359    max_val = atol(tmp);
     360    paranoid_free(tmp);
     361
    392362    mds = media_descriptor_string(bkpinfo->backup_media_type);
    393     sprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number);
     363    mr_asprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number);
    394364
    395365    open_progress_form("Comparing files",
     
    403373        insist_on_this_cd_number(g_current_media_number);
    404374        update_progress_form(progress_str);
    405         sprintf(tarball_fname,
    406                 MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number);
     375        mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number);
    407376
    408377        if (!does_file_exist(tarball_fname)) {
    409             sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",
    410                     current_tarball_number);
     378            mr_free(tarball_fname);
     379            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo", current_tarball_number);
    411380        }
    412381        if (!does_file_exist(tarball_fname)) {
    413             sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.gz",
    414                     current_tarball_number);
     382            mr_free(tarball_fname);
     383            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzma", current_tarball_number);
    415384        }
    416385        if (!does_file_exist(tarball_fname)) {
    417             sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.",
    418                     current_tarball_number);
     386            mr_free(tarball_fname);
     387            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.gz", current_tarball_number);
    419388        }
    420389        if (!does_file_exist(tarball_fname)) {
    421             sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2",
    422                     current_tarball_number);
     390            mr_free(tarball_fname);
     391            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.", current_tarball_number);
    423392        }
    424393        if (!does_file_exist(tarball_fname)) {
    425             sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.",
    426                     current_tarball_number);
     394            mr_free(tarball_fname);
     395            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2", current_tarball_number);
     396        }
     397        if (!does_file_exist(tarball_fname)) {
     398            mr_free(tarball_fname);
     399            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", current_tarball_number);
    427400        }
    428401        if (!does_file_exist(tarball_fname)) {
     
    432405                == 0) {
    433406                log_msg(2, "OK, I think I'm done with tarballs...");
     407                mr_free(tarball_fname);
    434408                break;
    435409            }
    436410            log_msg(2, "OK, I think it's time for another CD...");
    437411            g_current_media_number++;
    438             sprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number);
     412
     413            mr_free(progress_str);
     414            mr_asprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number);
    439415            log_to_screen(progress_str);
    440416        } else {
     
    444420            current_tarball_number++;
    445421        }
    446     }
     422        mr_free(tarball_fname);
     423    }
     424    mr_free(progress_str);
    447425    mr_free(mds);
    448426
     
    453431        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    454432    }
    455     paranoid_free(tarball_fname);
    456     paranoid_free(progress_str);
    457     paranoid_free(tmp);
    458433    return (retval);
    459434}
     
    478453{
    479454  /** needs malloc *********/
    480     char *tmp, *cwd, *new, *command;
     455    char *tmp = NULL;
     456    char *cwd, *new;
     457    char *command = NULL;
    481458    int resA = 0;
    482459    int resB = 0;
     
    486463    malloc_string(cwd);
    487464    malloc_string(new);
    488     malloc_string(command);
    489465
    490466    assert(bkpinfo != NULL);
     
    509485    noof_changed_files = count_lines_in_file(MONDO_CACHE"/changed.txt");
    510486    if (noof_changed_files) {
    511         sprintf(tmp, "%ld files do not match the backup            ",
    512                 noof_changed_files);
    513         //      mvaddstr_and_log_it( g_currentY++, 0, tmp );
    514         log_to_screen(tmp);
    515         sprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE);
     487        log_to_screen("%ld files do not match the backup            ", noof_changed_files);
     488
     489        mr_asprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE);
    516490        paranoid_system(command);
    517     } else {
    518         sprintf(tmp, "All files match the backup                     ");
     491        mr_free(command);
     492    } else {
     493        mr_asprintf(tmp, "All files match the backup                     ");
    519494        mvaddstr_and_log_it(g_currentY++, 0, tmp);
    520495        log_to_screen(tmp);
    521     }
    522 
    523     paranoid_free(tmp);
     496        mr_free(tmp);
     497    }
     498
    524499    paranoid_free(cwd);
    525500    paranoid_free(new);
    526     paranoid_free(command);
    527501
    528502    return (resA + resB);
     
    552526    int res = 0;
    553527    long q;
    554     char *tmp;
     528    char *tmp = NULL;
    555529    char *new;
    556530    char *cwd;
    557531
    558     malloc_string(tmp);
    559532    malloc_string(new);
    560533    malloc_string(cwd);
     
    630603        } else {
    631604            q = count_lines_in_file(MONDO_CACHE"/changed.files");
    632             sprintf(tmp, "%ld significant difference%s found.", q,
    633                     (q != 1) ? "s" : "");
     605            mr_asprintf(tmp, "%ld significant difference%s found.", q, (q != 1) ? "s" : "");
    634606            mvaddstr_and_log_it(g_currentY++, 0, tmp);
    635607            log_to_screen(tmp);
    636 
    637             strcpy(tmp,
    638                   "Type 'less /tmp/changed.files' for a list of non-matching files");
     608            mr_free(tmp);
     609
     610            mr_asprintf(tmp, "Type 'less /tmp/changed.files' for a list of non-matching files");
    639611            mvaddstr_and_log_it(g_currentY++, 0, tmp);
    640612            log_to_screen(tmp);
     613            mr_free(tmp);
    641614
    642615            log_msg(2, "calling popup_changelist_from_file()");
     
    663636
    664637    kill_petris();
    665     paranoid_free(tmp);
    666638    paranoid_free(new);
    667639    paranoid_free(cwd);
     
    686658
    687659  /** needs malloc **/
    688     char *dir, *command;
     660    char *dir;
     661    char *command = NULL;
    689662
    690663    assert(bkpinfo != NULL);
    691664    malloc_string(dir);
    692     malloc_string(command);
    693665    if (getcwd(dir, MAX_STR_LEN)) {
    694666        // FIXME
     
    698670    }
    699671
    700     sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
    701             bkpinfo->restore_path);
     672    mr_asprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path);
    702673    run_program_and_log_output(command, FALSE);
    703     mvaddstr_and_log_it(g_currentY,
    704                         0, "Verifying archives against filesystem");
     674    mr_free(command);
     675    mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem");
    705676
    706677    if (bkpinfo->disaster_recovery
     
    726697    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    727698    paranoid_free(dir);
    728     paranoid_free(command);
    729699    return (res);
    730700}
     
    749719{
    750720    int res;
    751     char *dir, *command;
     721    char *dir;
     722    char *command = NULL;
    752723
    753724    assert(bkpinfo != NULL);
    754725    malloc_string(dir);
    755     malloc_string(command);
    756726
    757727    if (getcwd(dir, MAX_STR_LEN)) {
     
    761731        // FIXME
    762732    }
    763     sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
    764             bkpinfo->restore_path);
     733    mr_asprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path);
    765734    run_program_and_log_output(command, FALSE);
    766     mvaddstr_and_log_it(g_currentY,
    767                         0, "Verifying archives against filesystem");
     735    mr_free(command);
     736
     737    mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem");
    768738    res = verify_tape_backups();
    769739    if (chdir(dir)) {
     
    776746    }
    777747    paranoid_free(dir);
    778     paranoid_free(command);
    779748    return (res);
    780749}
  • branches/3.2/mondo/src/mondorestore/mondo-rstr-newt.c

    r3185 r3193  
    1212#include "mondo-rstr-newt.h"
    1313#include "mr_mem.h"
     14#include "mr_str.h"
    1415
    1516//static char cvsid[] = "$Id$";
     
    5253{
    5354    /** buffers ***********************************************************/
    54     char tmp[MAX_STR_LEN];
     55    char *tmp = NULL;
    5556
    5657    /** newt **************************************************************/
     
    7879    newtPushHelpLine
    7980        ("   Add one of the following unallocated RAID partitions to this RAID device.");
    80     sprintf(tmp, "%-26s %s", "Device", "Size");
     81    mr_asprintf(tmp, "%-26s %s", "Device", "Size");
    8182    headerMsg = newtLabel(1, 1, tmp);
    8283    partitionsListbox =
     
    104105
    105106            items = disklist->entries;
    106             strcpy(disklist->el[items].device,
    107                    unallocated_raid_partitions->el[currline].device);
     107            strcpy(disklist->el[items].device, unallocated_raid_partitions->el[currline].device);
    108108            disklist->el[items].index = index;
    109109            disklist->entries = ++items;
     
    112112    }
    113113    newtFormDestroy(myForm);
     114    mr_free(tmp);
    114115    newtPopWindow();
    115116    newtPopHelpLine();
     
    152153
    153154    /** buffers **********************************************************/
    154     char drive_to_add[MAX_STR_LEN];
    155     char mountpoint_str[MAX_STR_LEN];
    156     char size_str[MAX_STR_LEN];
    157     char device_str[MAX_STR_LEN];
    158     char format_str[MAX_STR_LEN];
     155    char *drive_to_add = NULL;
     156    char *mountpoint_str = NULL;
     157    char *size_str = NULL;
     158    char *device_str = NULL;
     159    char *format_str = NULL;
    159160
    160161    /** pointers *********************************************************/
     
    169170    assert(keylist != NULL);
    170171
    171     strcpy(device_str, "/dev/");
    172     strcpy(mountpoint_str, "/");
     172    mr_asprintf(device_str, "/dev/");
     173    mr_asprintf(mountpoint_str, "/");
     174    mr_asprintf(size_str, "");
    173175#ifdef __FreeBSD__
    174     strcpy(format_str, "ufs");
     176    mr_asprintf(format_str, "ufs");
    175177#else
    176     strcpy(format_str, "ext3");
     178    mr_asprintf(format_str, "ext3");
    177179#endif
    178     size_str[0] = '\0';
    179     /* sprintf(size_str,""); */
    180180    newtOpenWindow(20, 5, 48, 10, "Add entry");
    181181    label0 = newtLabel(2, 1, "Device:    ");
     
    183183    label2 = newtLabel(2, 3, "Size (MB): ");
    184184    label3 = newtLabel(2, 4, "Format:    ");
    185     deviceComp =
    186         newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
    187     mountpointComp =
    188         newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
    189     formatComp =
    190         newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
     185    deviceComp = newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
     186    mountpointComp = newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
     187    formatComp = newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
    191188    sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0);
    192189    bOK = newtButton(5, 6, "  OK  ");
     
    200197    for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
    201198        b_res = newtRunForm(myForm);
    202         strcpy(device_str, device_here);
    203         strcpy(mountpoint_str, mountpoint_here);
    204         strcpy(format_str, format_here);
    205         strcpy(size_str, size_here);
    206 //      log_it ("Originals = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
    207         strip_spaces(device_str);
    208         strip_spaces(mountpoint_str);
    209         strip_spaces(format_str);
    210         strip_spaces(size_str);
    211 //      log_it ("Modified = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
     199        mr_free(device_str);
     200        mr_asprintf(device_str, "%s", device_here);
     201
     202        mr_free(mountpoint_str);
     203        mr_asprintf(mountpoint_str, "%s", mountpoint_here);
     204        mr_strip_spaces(mountpoint_str);
     205
     206        mr_free(format_str);
     207        mr_asprintf(format_str, "%s", format_here);
     208        mr_strip_spaces(format_str);
     209
     210        mr_free(size_str);
     211        mr_asprintf(size_str, "%s", size_here);
     212        mr_strip_spaces(size_str);
     213
     214        mr_strip_spaces(device_str);
    212215        if (b_res == bOK) {
    213216            if (device_str[strlen(device_str) - 1] == '/') {
     
    215218                b_res = NULL;
    216219            }
    217             if (size_of_specific_device_in_mountlist(mountlist, device_str)
    218                 >= 0) {
     220            if (size_of_specific_device_in_mountlist(mountlist, device_str) >= 0) {
    219221                popup_and_OK("Can't add this - you've got one already!");
    220222                b_res = NULL;
     
    228230        return;
    229231    }
    230     strcpy(drive_to_add, device_str);
     232    mr_asprintf(drive_to_add, "%s", device_str);
    231233    for (i = strlen(drive_to_add); isdigit(drive_to_add[i - 1]); i--);
    232     drive_to_add[i] = '\0';
     234    mr_free(drive_to_add);
     235
    233236    currline = mountlist->entries;
    234237    strcpy(mountlist->el[currline].device, device_str);
    235238    strcpy(mountlist->el[currline].mountpoint, mountpoint_str);
     239    mr_free(mountpoint_str);
     240
    236241    strcpy(mountlist->el[currline].format, format_str);
     242    mr_free(format_str);
     243
    237244    mountlist->el[currline].size = atol(size_str) * 1024L;
     245    mr_free(size_str);
     246
    238247    mountlist->entries++;
    239248    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
    240         initiate_new_raidlist_entry(raidlist, mountlist, currline,
    241                                     device_str);
    242     }
     249        initiate_new_raidlist_entry(raidlist, mountlist, currline, device_str);
     250    }
     251    mr_free(device_str);
     252
    243253    redraw_mountlist(mountlist, keylist, listbox);
    244254}
     
    315325
    316326    /** buffers ***********************************************************/
    317     char tmp[MAX_STR_LEN];
    318 
    319 
    320 
     327    char tmp = NULL;
     328    char *devname = NULL;
    321329
    322330    for (i = 0;
     
    324332         && strcmp(raidlist->el[i].volname, basename(raid_device)); i++);
    325333    if (i == raidlist->entries) {
    326         sprintf(tmp,
    327                 "Cannot calc size of raid device %s - cannot find it in raidlist",
    328                 raid_device);
    329         log_it(tmp);
     334        log_it("Cannot calc size of raid device %s - cannot find it in raidlist", raid_device);
    330335        return (0);             // Isn't this more sensible than 999999999? If the raid dev !exists,
    331336        // then it has no size, right?
     
    339344        int k = 0, l = 0;
    340345        for (k = 0; k < raidrec->plex[j].subdisks; ++k) {
    341             char devname[64];
    342             strcpy(devname, raidrec->plex[j].sd[k].which_device);
     346            mr_asprintf(devname, "%s", raidrec->plex[j].sd[k].which_device);
    343347            for (l = 0; l < raidlist->disks.entries; ++l) {
    344348                if (!strcmp(devname, raidlist->disks.el[l].name)) {
     
    368372                }
    369373            }
     374            mr_free(devname);
    370375        }
    371376
     
    388393    }
    389394
    390     sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device,
    391             (long) smallest_plex);
    392     log_it(tmp);
     395    log_it("I have calculated %s's real size to be %ld", raid_device, (long) smallest_plex);
    393396    return (smallest_plex);
    394397#else
     
    407410    long sp = 0;
    408411
    409     /** buffers ***********************************************************/
    410     char tmp[MAX_STR_LEN];
    411 
    412412    assert(mountlist != NULL);
    413413    assert(raidlist != NULL);
     
    418418         && strcmp(raidlist->el[i].raid_device, raid_device); i++);
    419419    if (i == raidlist->entries) {
    420         sprintf(tmp,
    421                 "Cannot calc size of raid device %s - cannot find it in raidlist",
    422                 raid_device);
    423         log_it(tmp);
     420        log_it("Cannot calc size of raid device %s - cannot find it in raidlist", raid_device);
    424421        return (999999999);
    425422    }
     
    444441        total_size = smallest_partition * (noof_partitions - 1);
    445442    }
    446     sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device,
    447             (long) total_size);
    448     log_it(tmp);
     443    log_it("I have calculated %s's real size to be %ld", raid_device, (long) total_size);
    449444    return (total_size);
    450445#endif
     
    470465    /** buffers ***********************************************************/
    471466    char tmp[MAX_STR_LEN];
    472     char prompt[MAX_STR_LEN];
     467    char *prompt = NULL;
    473468    char sz[MAX_STR_LEN];
    474469
    475     sprintf(prompt,
    476             "Please enter the RAID level you want. (concat, striped, raid5)");
     470    mr_asprintf(prompt, "Please enter the RAID level you want. (concat, striped, raid5)");
    477471    if (raidrec->raidlevel == -1) {
    478472        strcpy(tmp, "concat");
     
    485479        res = popup_and_get_string("Specify RAID level", prompt, tmp, 10);
    486480        if (!res) {
     481            mr_free(prompt);
    487482            return;
    488483        }
     
    502497        log_it(tmp);
    503498        if (is_this_raid_personality_registered(out)) {
    504             log_it
    505                 ("Groovy. You've picked a RAID personality which is registered.");
     499            log_it("Groovy. You've picked a RAID personality which is registered.");
    506500        } else {
    507             if (ask_me_yes_or_no
    508                 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
     501            if (ask_me_yes_or_no("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
    509502            {
    510503                out = 999;
     
    512505        }
    513506    }
     507    mr_free(prompt);
     508
    514509    raidrec->raidlevel = out;
    515510#else
    516511    /** buffers ***********************************************************/
    517512    char tmp[MAX_STR_LEN];
    518     char personalities[MAX_STR_LEN];
    519     char prompt[MAX_STR_LEN];
     513    char *personalities = NULL;
     514    char *prompt = NULL;
    520515    char sz[MAX_STR_LEN];
    521     int out = 0, res = 0;
     516    int out = 0;
     517    int res = 0;
    522518
    523519
    524520    assert(raidrec != NULL);
    525521    paranoid_system("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null");
    526     strcpy(personalities,
    527            last_line_of_file("/tmp/raid-personalities.txt"));
    528     sprintf(prompt, "Please enter the RAID level you want. %s",
    529             personalities);
     522    mr_asprintf(personalities, "%s", last_line_of_file("/tmp/raid-personalities.txt"));
     523    mr_asprintf(prompt, "Please enter the RAID level you want. %s", personalities);
     524    mr_free(personalities);
     525
    530526    if (raidrec->raid_level == -1) {
    531527        strcpy(tmp, "linear");
     
    555551        log_it(tmp);
    556552        if (is_this_raid_personality_registered(out)) {
    557             log_it
    558                 ("Groovy. You've picked a RAID personality which is registered.");
     553            log_it("Groovy. You've picked a RAID personality which is registered.");
    559554        } else {
    560             if (ask_me_yes_or_no
    561                 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
    562             {
     555            if (ask_me_yes_or_no("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) {
    563556                out = 999;
    564557            }
    565558        }
    566559    }
     560    mr_free(prompt);
     561
    567562    raidrec->raid_level = out;
    568563#endif
     
    589584    int pos = 0;
    590585
    591     /** buffers ***********************************************************/
    592     char tmp[MAX_STR_LEN];
    593 
    594586    assert(mountlist != NULL);
    595587    assert(raidlist != NULL);
     
    602594             pos++);
    603595        if (pos < mountlist->entries) {
    604             sprintf(tmp,
    605                     "Deleting partition %s cos it was part of a now-defunct RAID",
    606                     mountlist->el[pos].device);
    607             log_it(tmp);
     596            log_it("Deleting partition %s cos it was part of a now-defunct RAID", mountlist->el[pos].device);
     597
    608598            memcpy((void *) &mountlist->el[pos],
    609599                   (void *) &mountlist->el[mountlist->entries - 1],
     
    631621    /** int ***************************************************************/
    632622    int pos = 0;
     623    int res = 0;
    633624
    634625    /** buffers ***********************************************************/
    635     char tmp[MAX_STR_LEN];
     626    char *tmp = NULL;
    636627
    637628    assert(disklist != NULL);
    638629    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    639630
    640     sprintf(tmp, "Delete %s from RAID device %s - are you sure?",
    641             disklist->el[currline].device, raid_device);
    642     if (!ask_me_yes_or_no(tmp)) {
     631    mr_asprintf(tmp, "Delete %s from RAID device %s - are you sure?", disklist->el[currline].device, raid_device);
     632    res = ask_me_yes_or_no(tmp);
     633    mr_free(tmp);
     634
     635    if (!res) {
    643636        return;
    644637    }
    645638    for (pos = currline; pos < disklist->entries - 1; pos++) {
    646         /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */
    647639        strcpy(disklist->el[pos].device, disklist->el[pos + 1].device);
    648640    }
     
    670662    /** int ***************************************************************/
    671663    int pos = 0;
     664    int res = 0;
    672665
    673666    /** buffers ***********************************************************/
    674     char tmp[MAX_STR_LEN];
    675     char device[MAX_STR_LEN];
     667    char *tmp = NULL;
     668    char *device = NULL;
    676669
    677670
     
    681674    assert(keylist != NULL);
    682675
    683     pos =
    684         which_raid_device_is_using_this_partition(raidlist,
    685                                                   mountlist->el[currline].
    686                                                   device);
     676    pos = which_raid_device_is_using_this_partition(raidlist, mountlist->el[currline].device);
    687677    if (pos >= 0) {
    688         sprintf(tmp, "Cannot delete %s: it is in use by RAID device %s",
    689                 mountlist->el[currline].device,
    690                 raidlist->el[pos].OSSWAP(raid_device, volname));
     678        mr_asprintf(tmp, "Cannot delete %s: it is in use by RAID device %s", mountlist->el[currline].device, raidlist->el[pos].OSSWAP(raid_device, volname));
    691679        popup_and_OK(tmp);
     680        mr_free(tmp);
    692681        return;
    693682    }
    694     sprintf(tmp, "Delete %s - are you sure?",
    695             mountlist->el[currline].device);
    696     if (!ask_me_yes_or_no(tmp)) {
     683    mr_asprintf(tmp, "Delete %s - are you sure?", mountlist->el[currline].device);
     684    res = ask_me_yes_or_no(tmp);
     685    mr_free(tmp);
     686
     687    if (!res) {
    697688        return;
    698689    }
    699690    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
    700         strcpy(device, mountlist->el[currline].device);
     691        mr_asprintf(device, "%s", mountlist->el[currline].device);
    701692        delete_raidlist_entry(mountlist, raidlist, device);
    702693        for (currline = 0;
     
    704695             && strcmp(mountlist->el[currline].device, device);
    705696             currline++);
     697        mr_free(device);
     698
    706699        if (currline == mountlist->entries) {
    707700            log_it("Dev is gone. I can't delete it. Ho-hum");
     
    737730
    738731    /** buffers ***********************************************************/
    739     char tmp[MAX_STR_LEN];
     732    char *tmp = NULL;
    740733
    741734    assert(mountlist != NULL);
     
    747740        return;
    748741    }
    749     sprintf(tmp, "Do you want me to delete %s's partitions, too?", device);
     742    mr_asprintf(tmp, "Do you want me to delete %s's partitions, too?", device);
    750743    delete_partitions_too = ask_me_yes_or_no(tmp);
    751744    if (delete_partitions_too) {
     
    760753                    if (!strcmp(raidlist->el[i].plex[x].sd[y].which_device,
    761754                                raidlist->disks.el[z].name)) {
    762                         strcpy(d.el[d.entries].name,
    763                                raidlist->disks.el[z].name);
    764                         strcpy(d.el[d.entries++].device,
    765                                raidlist->disks.el[z].device);
     755                        strcpy(d.el[d.entries].name, raidlist->disks.el[z].name);
     756                        strcpy(d.el[d.entries++].device, raidlist->disks.el[z].device);
    766757                    }
    767758                }
     
    791782        items--;
    792783    }
     784    mr_free(tmp);
    793785    raidlist->entries = items;
    794786}
     
    806798
    807799    /** buffers ************************************************************/
    808     char tmp[MAX_STR_LEN];
     800    char *tmp = NULL;
     801    int res = 0;
    809802
    810803    /** structures *********************************************************/
     
    814807
    815808    av = &raidrec->additional_vars;
    816     sprintf(tmp, "Delete %s - are you sure?", av->el[lino].label);
    817     if (ask_me_yes_or_no(tmp)) {
     809    mr_asprintf(tmp, "Delete %s - are you sure?", av->el[lino].label);
     810    res = ask_me_yes_or_no(tmp);
     811    mr_free(tmp);
     812
     813    if (res) {
    818814        if (!strcmp(av->el[lino].label, "persistent-superblock")
    819815            || !strcmp(av->el[lino].label, "chunk-size")) {
    820             sprintf(tmp, "%s must not be deleted. It would be bad.",
    821                     av->el[lino].label);
     816            mr_asprintf(tmp, "%s must not be deleted. It would be bad.", av->el[lino].label);
    822817            popup_and_OK(tmp);
     818            mr_free(tmp);
    823819        } else {
    824820            memcpy((void *) &av->el[lino], (void *) &av->el[av->entries--],
     
    856852    static char current_filename[MAX_STR_LEN];
    857853    char tmp[MAX_STR_LEN + 2];
     854    char *tmp1 = NULL;
    858855
    859856    /** bool *************************************************************/
     
    886883                if (!warned_already) {
    887884                    warned_already = TRUE;
    888                     sprintf(tmp,
    889                             "Too many lines. Displaying first %d entries only. Close a directory to see more.",
    890                             ARBITRARY_MAXIMUM);
    891                     popup_and_OK(tmp);
     885                    mr_asprintf(tmp1, "Too many lines. Displaying first %d entries only. Close a directory to see more.", ARBITRARY_MAXIMUM);
     886                    popup_and_OK(tmp1);
     887                    mr_free(tmp1);
    892888                }
    893889            } else {
    894                 strcpy(g_strings_of_flist_window[lines_in_flist_window],
    895                        current_filename);
     890                strcpy(g_strings_of_flist_window[lines_in_flist_window], current_filename);
    896891                g_is_path_selected[lines_in_flist_window] = node->selected;
    897892                lines_in_flist_window++;
     
    908903                (g_strings_of_flist_window[i],
    909904                 g_strings_of_flist_window[i - 1]) < 0) {
    910                 strcpy(tmp, g_strings_of_flist_window[i]);
    911                 strcpy(g_strings_of_flist_window[i],
    912                        g_strings_of_flist_window[i - 1]);
    913                 strcpy(g_strings_of_flist_window[i - 1], tmp);
     905                mr_asprintf(tmp1, "%s", g_strings_of_flist_window[i]);
     906                strcpy(g_strings_of_flist_window[i], g_strings_of_flist_window[i - 1]);
     907                strcpy(g_strings_of_flist_window[i - 1], tmp1);
     908                mr_free(tmp1);
     909
    914910                dummybool = g_is_path_selected[i];
    915911                g_is_path_selected[i] = g_is_path_selected[i - 1];
     
    10141010    void *curr_choice;
    10151011    void *keylist[ARBITRARY_MAXIMUM];
    1016 
    1017     /** buffers ***********************************************************/
    1018     char tmp[MAX_STR_LEN];
    10191012
    10201013    /** bool **************************************************************/
     
    10641057                indexno = 0;
    10651058            }
    1066             sprintf(tmp, "You selected '%s'",
    1067                     g_strings_of_flist_window[indexno]);
    1068             log_it(tmp);
     1059            log_it("You selected '%s'", g_strings_of_flist_window[indexno]);
     1060
    10691061            if (b_res == bMore) {
    10701062                g_is_path_expanded[indexno] = TRUE;
     
    11581150
    11591151  /** buffers ***********************************************************/
    1160     char device_str[MAX_STR_LEN];
    1161     char mountpoint_str[MAX_STR_LEN];
    1162     char size_str[MAX_STR_LEN];
    1163     char format_str[MAX_STR_LEN];
    1164     char tmp[MAX_STR_LEN];
    1165     char device_used_to_be[MAX_STR_LEN];
    1166     char mountpt_used_to_be[MAX_STR_LEN];
     1152    char *device_str = NULL;
     1153    char *mountpoint_str = NULL;
     1154    char *size_str = NULL;
     1155    char *format_str = NULL;
     1156    char *tmp = NULL;
     1157    char *device_used_to_be = NULL;
     1158    char *mountpt_used_to_be = NULL;
    11671159
    11681160    /** pointers **********************************************************/
     
    11821174    memcpy((void *) &bkp_raidlist, (void *) raidlist,
    11831175           sizeof(struct raidlist_itself));
    1184     strcpy(device_str, mountlist->el[currline].device);
    1185     strcpy(device_used_to_be, mountlist->el[currline].device);
    1186     strcpy(mountpoint_str, mountlist->el[currline].mountpoint);
    1187     strcpy(mountpt_used_to_be, mountlist->el[currline].mountpoint);
    1188     strcpy(format_str, mountlist->el[currline].format);
    1189     sprintf(size_str, "%lld", mountlist->el[currline].size / 1024L);
     1176    mr_asprintf(device_str, "%s", mountlist->el[currline].device);
     1177    mr_asprintf(device_used_to_be, "%s", mountlist->el[currline].device);
     1178    mr_asprintf(mountpoint_str, "%s", mountlist->el[currline].mountpoint);
     1179    mr_asprintf(mountpt_used_to_be, "%s", mountlist->el[currline].mountpoint);
     1180    mr_asprintf(format_str, "%s", mountlist->el[currline].format);
     1181    mr_asprintf(size_str, "%lld", mountlist->el[currline].size / 1024L);
    11901182    newtOpenWindow(20, 5, 48, 10, "Edit entry");
    11911183    label0 = newtLabel(2, 1, "Device:");
     
    11931185    label2 = newtLabel(2, 3, "Size (MB): ");
    11941186    label3 = newtLabel(2, 4, "Format:    ");
    1195     deviceComp =
    1196         newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
    1197     mountpointComp =
    1198         newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
    1199     formatComp =
    1200         newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
     1187    deviceComp = newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
     1188    mountpointComp = newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
     1189    formatComp = newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
    12011190    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
    12021191        || !strcmp(mountlist->el[currline].mountpoint, "image")) {
     
    12181207    for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
    12191208        b_res = newtRunForm(myForm);
    1220         strcpy(device_str, device_here);
    1221         strip_spaces(device_str);
    1222         strcpy(mountpoint_str, mountpoint_here);
    1223         strip_spaces(mountpoint_str);
    1224         strcpy(format_str, format_here);
    1225         strip_spaces(format_str);
     1209        mr_free(device_str);
     1210        mr_asprintf(device_str, "%s", device_here);
     1211        mr_strip_spaces(device_str);
     1212
     1213        mr_free(mountpoint_str);
     1214        mr_asprintf(mountpoint_str, "%s", mountpoint_here);
     1215        mr_strip_spaces(mountpoint_str);
     1216
     1217        mr_free(format_str);
     1218        mr_asprintf(format_str, "%s", format_here);
     1219        mr_strip_spaces(format_str);
     1220
    12261221        if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB)
    12271222            && strstr(device_used_to_be, RAID_DEVICE_STUB)
     
    12381233        if (!strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
    12391234            && strcmp(mountlist->el[currline].mountpoint, "image")) {
    1240             strcpy(size_str, size_here);
    1241             strip_spaces(size_str);
     1235            mr_free(size_str);
     1236            mr_asprintf(size_str, "%s", size_here);
     1237            mr_strip_spaces(size_str);
    12421238        } else {
    1243             sprintf(size_str, "%ld",
    1244                     calculate_raid_device_size(mountlist, raidlist,
    1245                                                mountlist->el[currline].
    1246                                                device) / 1024);
     1239            mr_asprintf(size_str, "%ld", calculate_raid_device_size(mountlist, raidlist, mountlist->el[currline].device) / 1024);
    12471240            newtLabelSetText(sizeComp, size_str);
    12481241        }
     
    12611254                                                 device);
    12621255                if (j < 0) {
    1263                     sprintf(tmp,
    1264                             "/etc/raidtab does not have an entry for %s; please delete it and add it again",
    1265                             mountlist->el[currline].device);
     1256                    mr_asprintf(tmp, "/etc/raidtab does not have an entry for %s; please delete it and add it again", mountlist->el[currline].device);
    12661257                    popup_and_OK(tmp);
     1258                    mr_free(tmp);
    12671259                } else {
    12681260                    log_it("edit_raidlist_entry - calling");
     
    12761268    newtPopHelpLine();
    12771269    newtPopWindow();
     1270    mr_free(mountpt_used_to_be);
     1271
    12781272    if (b_res == bCancel) {
    12791273        memcpy((void *) raidlist, (void *) &bkp_raidlist,
    12801274               sizeof(struct raidlist_itself));
     1275        mr_free(device_str);
     1276        mr_free(device_used_to_be);
     1277        mr_free(format_str);
     1278        mr_free(size_str);
    12811279        return;
    12821280    }
    12831281    strcpy(mountlist->el[currline].device, device_str);
    12841282    strcpy(mountlist->el[currline].mountpoint, mountpoint_str);
     1283    mr_free(mountpoint_str);
     1284
    12851285    strcpy(mountlist->el[currline].format, format_str);
     1286    mr_free(format_str);
     1287
    12861288    if (strcmp(mountlist->el[currline].mountpoint, "image")) {
    12871289        if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
     
    12931295        }
    12941296    }
     1297    mr_free(size_str);
    12951298    newtListboxSetEntry(listbox, (long) keylist[currline],
    12961299                        mountlist_entry_to_string(mountlist, currline));
     
    12981301    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
    12991302        && !strstr(device_used_to_be, RAID_DEVICE_STUB)) {
    1300         initiate_new_raidlist_entry(raidlist, mountlist, currline,
    1301                                     device_str);
     1303        initiate_new_raidlist_entry(raidlist, mountlist, currline, device_str);
    13021304    }
    13031305    /* if moving from RAID to non-RAID then do funky stuff */
     
    13161318#ifndef __FreeBSD__             /* It works fine under FBSD. */
    13171319    else if (strcmp(device_used_to_be, device_str)) {
    1318         popup_and_OK
    1319             ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it.");
     1320        popup_and_OK("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it.");
    13201321    }
    13211322#endif
     1323    mr_free(device_str);
     1324    mr_free(device_used_to_be);
     1325
    13221326    redraw_mountlist(mountlist, keylist, listbox);
    13231327}
     
    13421346    for (i = 0; i < raidlist->disks.entries; ++i) {
    13431347        if (!strcmp(raidlist->disks.el[i].device, temp)) {
    1344             strcpy(raidrec->sd[raidrec->subdisks].which_device,
    1345                    raidlist->disks.el[i].name);
     1348            strcpy(raidrec->sd[raidrec->subdisks].which_device, raidlist->disks.el[i].name);
    13461349            found = TRUE;
    13471350        }
    13481351    }
    13491352    if (!found) {
    1350         sprintf(raidlist->disks.el[raidlist->disks.entries].name,
    1351                 "drive%i", raidlist->disks.entries);
    1352         sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i",
    1353                 raidlist->disks.entries);
     1353        sprintf(raidlist->disks.el[raidlist->disks.entries].name, "drive%i", raidlist->disks.entries);
     1354        sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i", raidlist->disks.entries);
    13541355        strcpy(raidlist->disks.el[raidlist->disks.entries++].device, temp);
    13551356    }
     
    14241425    void *keylist[10];
    14251426    void *curr_choice;
     1427    char *raidlevel = NULL;
     1428    char *chunksize = NULL;
     1429    char *msg = NULL;
    14261430
    14271431    int currline2 = 0;
     1432    int res = 0;
    14281433
    14291434    log_it("Started edit_raidlist_entry");
     
    14551460            keylist[i] = (void *) i;
    14561461            if (i < raidrec->plexes) {
    1457                 char pname[64], entry[MAX_STR_LEN], raidlevel[64],
    1458                     chunksize[64];
     1462                char pname[64], entry[MAX_STR_LEN];
    14591463                switch (raidrec->plex[i].raidlevel) {
    14601464                case -1:
    1461                     strcpy(raidlevel, "concat");
     1465                    mr_asprintf(raidlevel, "concat");
    14621466                    break;
    14631467                case 0:
    1464                     strcpy(raidlevel, "striped");
     1468                    mr_asprintf(raidlevel, "striped");
    14651469                    break;
    14661470                case 5:
    1467                     strcpy(raidlevel, "raid5");
     1471                    mr_asprintf(raidlevel, "raid5");
    14681472                    break;
    14691473                default:
    1470                     sprintf(raidlevel, "raid%i",
    1471                             raidrec->plex[i].raidlevel);
     1474                    mr_asprintf(raidlevel, "raid%i", raidrec->plex[i].raidlevel);
    14721475                    break;
    14731476                }
    14741477
    14751478                if (raidrec->plex[i].raidlevel == -1) {
    1476                     strcpy(chunksize, "N/A");
     1479                    mr_asprintf(chunksize, "N/A");
    14771480                } else {
    1478                     sprintf(chunksize, "%dk", raidrec->plex[i].stripesize);
     1481                    mr_asprintf(chunksize, "%dk", raidrec->plex[i].stripesize);
    14791482                }
    14801483                snprintf(pname, 64, "%s.p%i", raidrec->volname, i);
     
    14821485                         pname, raidlevel, chunksize,
    14831486                         raidrec->plex[i].subdisks);
     1487                mr_free(raidlevel);
     1488                mr_free(chunksize);
     1489
    14841490                newtListboxAppendEntry(plexesListbox, entry, keylist[i]);
    14851491            }
     
    15031509
    15041510        if (b_res == bDelete) {
    1505             char msg[MAX_STR_LEN];
    1506             sprintf(msg, "Are you sure you want to delete %s.p%i?",
    1507                     raidrec->volname, currline2);
    1508             if (ask_me_yes_or_no(msg)) {
     1511            mr_asprintf(msg, "Are you sure you want to delete %s.p%i?", raidrec->volname, currline2);
     1512            res = ask_me_yes_or_no(msg);
     1513            mr_free(msg);
     1514
     1515            if (res) {
    15091516                log_it("Deleting RAID plex");
    15101517                memcpy((void *) &raidrec->plex[currline2],
     
    15401547    /** buffers ***********************************************************/
    15411548    char *title_of_editraidForm_window;
    1542     char *sz_raid_level;
    1543     char *sz_data_disks;
    1544     char *sz_spare_disks;
    1545     char *sz_parity_disks;
    1546     char *sz_failed_disks;
     1549    char *sz_raid_level = NULL;
     1550    char *sz_data_disks = NULL;
     1551    char *sz_spare_disks = NULL;
     1552    char *sz_parity_disks = NULL;
     1553    char *sz_failed_disks = NULL;
    15471554
    15481555    /** newt **************************************************************/
     
    15621569    assert(raidrec != NULL);
    15631570
    1564     malloc_string(title_of_editraidForm_window);
    1565     malloc_string(sz_raid_level);
    1566     malloc_string(sz_data_disks);
    1567     malloc_string(sz_spare_disks);
    1568     malloc_string(sz_parity_disks);
    1569     malloc_string(sz_failed_disks);
    1570     if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) {
    1571         fatal_error("Cannot malloc space for raidrec");
    1572     }
    1573 
     1571    bkp_raidrec = mr_malloc(sizeof(struct raid_device_record));
    15741572    log_it("Started edit_raidlist_entry");
    15751573
    1576     memcpy((void *) bkp_raidrec, (void *) raidrec,
    1577            sizeof(struct raid_device_record));
    1578     sprintf(title_of_editraidForm_window, "%s", raidrec->raid_device);
     1574    memcpy((void *) bkp_raidrec, (void *) raidrec, sizeof(struct raid_device_record));
     1575    mr_asprintf(title_of_editraidForm_window, "%s", raidrec->raid_device);
    15791576    log_msg(2, "Opening newt window");
    15801577    newtOpenWindow(20, 5, 40, 14, title_of_editraidForm_window);
    15811578    for (;;) {
    15821579        log_msg(2, "Main loop");
    1583         sprintf(title_of_editraidForm_window, "Edit %s",
    1584                 raidrec->raid_device);
    1585         strcpy(sz_raid_level,
    1586                turn_raid_level_number_to_string(raidrec->raid_level));
    1587         strcpy(sz_data_disks,
    1588                number_of_disks_as_string(raidrec->data_disks.entries,
    1589                                          "data"));
    1590         strcpy(sz_spare_disks,
    1591                number_of_disks_as_string(raidrec->spare_disks.entries,
    1592                                          "spare"));
    1593         strcpy(sz_parity_disks,
    1594                number_of_disks_as_string(raidrec->parity_disks.entries,
    1595                                          "parity"));
    1596         strcpy(sz_failed_disks,
    1597                number_of_disks_as_string(raidrec->failed_disks.entries,
    1598                                          "failed"));
     1580        mr_free(title_of_editraidForm_window);
     1581        mr_asprintf(title_of_editraidForm_window, "Edit %s", raidrec->raid_device);
     1582        mr_asprintf(sz_raid_level, "%s", turn_raid_level_number_to_string(raidrec->raid_level));
     1583        mr_asprintf(sz_data_disks, "%s", number_of_disks_as_string(raidrec->data_disks.entries, "data"));
     1584        mr_asprintf(sz_spare_disks, "%s", number_of_disks_as_string(raidrec->spare_disks.entries, "spare"));
     1585        mr_asprintf(sz_parity_disks, "%s", number_of_disks_as_string(raidrec->parity_disks.entries, "parity"));
     1586        mr_asprintf(sz_failed_disks, "%s", number_of_disks_as_string(raidrec->failed_disks.entries, "failed"));
    15991587        bSelectData = newtButton(1, 1, sz_data_disks);
    16001588        bSelectSpare = newtButton(20, 1, sz_spare_disks);
     
    16171605            choose_raid_level(raidrec);
    16181606        } else if (b_res == bSelectData) {
    1619             select_raid_disks(mountlist, raidlist, raidrec, "data",
    1620                               &raidrec->data_disks);
     1607            select_raid_disks(mountlist, raidlist, raidrec, "data", &raidrec->data_disks);
    16211608        } else if (b_res == bSelectSpare) {
    1622             select_raid_disks(mountlist, raidlist, raidrec, "spare",
    1623                               &raidrec->spare_disks);
     1609            select_raid_disks(mountlist, raidlist, raidrec, "spare", &raidrec->spare_disks);
    16241610        } else if (b_res == bSelectParity) {
    1625             select_raid_disks(mountlist, raidlist, raidrec, "parity",
    1626                               &raidrec->parity_disks);
     1611            select_raid_disks(mountlist, raidlist, raidrec, "parity", &raidrec->parity_disks);
    16271612        } else if (b_res == bSelectFailed) {
    1628             select_raid_disks(mountlist, raidlist, raidrec, "failed",
    1629                               &raidrec->failed_disks);
     1613            select_raid_disks(mountlist, raidlist, raidrec, "failed", &raidrec->failed_disks);
    16301614        } else if (b_res == bAdditional) {
    16311615            edit_raidrec_additional_vars(raidrec);
     
    16351619            break;
    16361620        }
     1621        mr_free(sz_data_disks);
     1622        mr_free(sz_spare_disks);
     1623        mr_free(sz_parity_disks);
     1624        mr_free(sz_failed_disks);
    16371625    }
    16381626    if (b_res == bCancel) {
    1639         memcpy((void *) raidrec, (void *) bkp_raidrec,
    1640                sizeof(struct raid_device_record));
     1627        memcpy((void *) raidrec, (void *) bkp_raidrec, sizeof(struct raid_device_record));
    16411628    }
    16421629    newtPopHelpLine();
    16431630    newtPopWindow();
    1644     mountlist->el[currline].size =
    1645         calculate_raid_device_size(mountlist, raidlist,
    1646                                    raidrec->raid_device);
    1647     paranoid_free(title_of_editraidForm_window);
    1648     paranoid_free(sz_raid_level);
    1649     paranoid_free(sz_data_disks);
    1650     paranoid_free(sz_spare_disks);
    1651     paranoid_free(sz_parity_disks);
    1652     paranoid_free(sz_failed_disks);
     1631    mountlist->el[currline].size = calculate_raid_device_size(mountlist, raidlist, raidrec->raid_device);
     1632    mr_free(title_of_editraidForm_window);
     1633    mr_free(sz_raid_level);
    16531634    paranoid_free(bkp_raidrec);
    16541635#endif
     
    16781659
    16791660    /** buffers ***********************************************************/
    1680     char title_of_editraidForm_window[MAX_STR_LEN];
     1661    char *title_of_editraidForm_window = NULL;
    16811662
    16821663    /** newt **************************************************************/
     
    16971678    int currline_a, currline_u;
    16981679
     1680    char *p = NULL;
     1681    char *tmp = NULL;
     1682    char *entry = NULL;
     1683
    16991684    struct mountlist_itself *unallocparts;
    17001685
     
    17041689    memcpy((void *) &bkp_raidrec, (void *) raidrec,
    17051690           sizeof(struct vinum_plex));
    1706     sprintf(title_of_editraidForm_window, "%s.p%i",
    1707             raidlist->el[currline].volname, currline2);
     1691    mr_asprintf(title_of_editraidForm_window, "%s.p%i", raidlist->el[currline].volname, currline2);
    17081692    newtPushHelpLine
    17091693        ("   Please select a subdisk to edit, or edit this plex's parameters");
    17101694    newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window);
     1695    mr_free(title_of_editraidForm_window);
     1696
    17111697    for (;;) {
    17121698        int i;
    1713         char headerstr[MAX_STR_LEN];
    1714         char tmp[64];
    1715         snprintf(headerstr, MAX_STR_LEN, "%-24s %s", "Subdisk", "Device");
    1716 
    17171699
    17181700        switch (raidrec->raidlevel) {
    17191701        case -1:
    1720             strcpy(tmp, "concat");
     1702            mr_asprintf(tmp, "concat");
    17211703            break;
    17221704        case 0:
    1723             strcpy(tmp, "striped");
     1705            mr_asprintf(tmp, "striped");
    17241706            break;
    17251707        case 5:
    1726             strcpy(tmp, "raid5");
     1708            mr_asprintf(tmp, "raid5");
    17271709            break;
    17281710        default:
    1729             sprintf(tmp, "unknown (%i)", raidrec->raidlevel);
     1711            mr_asprintf(tmp, "unknown (%i)", raidrec->raidlevel);
    17301712            break;
    17311713        }
    17321714        bLevel = newtCompactButton(2, 2, " RAID level ");
    17331715        sLevel = newtLabel(19, 2, tmp);
     1716        mr_free(tmp);
    17341717
    17351718        if (raidrec->raidlevel >= 0) {
    1736             sprintf(tmp, "%ik", raidrec->stripesize);
     1719            mr_asprintf(tmp, "%ik", raidrec->stripesize);
    17371720            bStripeSize = newtCompactButton(2, 4, " Stripe size ");
    17381721        } else {
    1739             strcpy(tmp, "N/A");
     1722            mr_asprintf(tmp, "N/A");
    17401723            bStripeSize = newtLabel(2, 4, "Stripe size:");
    17411724        }
    17421725        sStripeSize = newtLabel(19, 4, tmp);
     1726        mr_free(tmp);
    17431727
    17441728        bOK = newtCompactButton(2, 16, "  OK  ");
     
    17491733
    17501734
    1751         //  plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1752         //  plexesHeader  = newtLabel (2, 6, headerstr);
    17531735        unallocListbox =
    17541736            newtListbox(2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     
    17661748                                                 raidlist);
    17671749        for (i = 0; i < ARBITRARY_MAXIMUM; ++i) {
    1768             char entry[MAX_STR_LEN];
    17691750            keylist[i] = (void *) i;
    17701751            if (i < raidrec->subdisks) {
    1771                 snprintf(entry, MAX_STR_LEN, "%-17s",
    1772                          find_dev_entry_for_raid_device_name(raidlist,
    1773                                                              raidrec->
    1774                                                              sd[i].
    1775                                                              which_device));
     1752                mr_asprintf(entry, "%-17s", find_dev_entry_for_raid_device_name(raidlist, raidrec->sd[i].which_device));
    17761753                newtListboxAppendEntry(allocListbox, entry, keylist[i]);
     1754                mr_free(entry);
    17771755            }
    17781756            if (i < unallocparts->entries) {
    1779                 snprintf(entry, MAX_STR_LEN, "%-17s",
    1780                          unallocparts->el[i].device);
     1757                mr_asprintf(entry, "%-17s", unallocparts->el[i].device);
    17811758                newtListboxAppendEntry(unallocListbox, entry, keylist[i]);
     1759                mr_free(entry);
    17821760            }
    17831761        }
     
    18301808            choose_raid_level(raidrec);
    18311809        } else if (b_res == bStripeSize) {
    1832             char tmp[64];
    1833             sprintf(tmp, "%i", raidrec->stripesize);
     1810            char tmp1[64];
     1811            sprintf(tmp1, "%i", raidrec->stripesize);
    18341812            if (popup_and_get_string
    18351813                ("Stripe size",
    1836                  "Please enter the stripe size in kilobytes.", tmp, 20)) {
    1837                 raidrec->stripesize = atoi(tmp);
     1814                 "Please enter the stripe size in kilobytes.", tmp1, 20)) {
     1815                raidrec->stripesize = atoi(tmp1);
    18381816            }
    18391817        } else if ((b_res == bAlloc) || (b_res == unallocListbox)) {
     
    18491827            }
    18501828        }
    1851 #if 0
    1852     } else {
    1853         edit_raid_subdisk(raidlist, raidrec, &raidrec->sd[currline3],
    1854                           currline3);
    1855     }
    1856 #endif
    18571829    newtFormDestroy(editraidForm);
    18581830    newtRefresh();
     
    18601832
    18611833if (b_res == bCancel) {
    1862     memcpy((void *) raidrec, (void *) &bkp_raidrec,
    1863            sizeof(struct vinum_plex));
     1834    memcpy((void *) raidrec, (void *) &bkp_raidrec, sizeof(struct vinum_plex));
    18641835}
    18651836newtPopWindow();
     
    18771848
    18781849    /** buffers ***********************************************************/
    1879     char header[MAX_STR_LEN];
    1880     char comment[MAX_STR_LEN];
     1850    char *header = NULL;
     1851    char *comment = NULL;
    18811852    char sz_out[MAX_STR_LEN];
    18821853
     
    18851856
    18861857    strcpy(sz_out, raidrec->additional_vars.el[lino].value);
    1887     sprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label);
    1888     sprintf(comment, "Please set %s's value (currently '%s')",
    1889             raidrec->additional_vars.el[lino].label, sz_out);
     1858    mr_asprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label);
     1859    mr_asprintf(comment, "Please set %s's value (currently '%s')", raidrec->additional_vars.el[lino].label, sz_out);
    18901860    if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) {
    18911861        strip_spaces(sz_out);
    18921862        strcpy(raidrec->additional_vars.el[lino].value, sz_out);
    18931863    }
    1894 }
    1895 
    1896 
    1897 /* I'm not racist against white people. I just don't like people who think Liberia is near Spain.       - Hugo, 09/01/2001 */
     1864    mr_free(header);
     1865    mr_free(comment);
     1866}
    18981867
    18991868#endif
     
    19361905
    19371906    /** buffers **********************************************************/
    1938     char tmp[MAX_STR_LEN];
     1907    char *tmp = NULL;
    19391908    char *flaws_str = NULL;
    19401909    char *flaws_str_A = NULL;
     
    19571926    bCancel = newtCompactButton(i += 12, 17, "Cancel");
    19581927    bOK = newtCompactButton(i += 12, 17, "  OK  ");
    1959     sprintf(tmp, "%-24s %-24s %-8s  %s", "Device", "Mountpoint", "Format", "Size (MB)");
     1928    mr_asprintf(tmp, "%-24s %-24s %-8s  %s", "Device", "Mountpoint", "Format", "Size (MB)");
    19601929    headerMsg = newtLabel(2, 1, tmp);
     1930    mr_free(tmp);
     1931
    19611932    flawsLabelA = newtLabel(2, 13, "         ");
    19621933    flawsLabelB = newtLabel(2, 14, "         ");
     
    20151986        } else if (b_res == bReload) {
    20161987            if (ask_me_yes_or_no("Reload original mountlist?")) {
    2017 /*
    2018 This would be really dumb. RAIDTAB_FNAME is #define'd.   --- Hugo, 2003/04/24
    2019           if (!RAIDTAB_FNAME[0])
    2020         {
    2021                   strcpy(RAIDTAB_FNAME, "/etc/raidtab");
    2022           log_it("Warning - raidtab_fname is blank. Assuming %s", g_raidtab_fname);
    2023         }
    2024 */
    20251988                load_mountlist(mountlist, mountlist_fname);
    20261989                load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     
    22372200    int i = 0;
    22382201#ifdef __FreeBSD__
    2239     char vdev[64];
     2202    char *vdev = NULL;
     2203    int res = 0;
    22402204#else
    22412205// Linux
     
    22472211#ifdef __FreeBSD__
    22482212    for (i = 0; i < raidlist->entries; i++) {
    2249         sprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname);
    2250         if (!strcmp(device, vdev))
     2213        mr_asprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname);
     2214        res = strcmp(device, vdev);
     2215        mr_free(vdev);
     2216
     2217        if (!res)
    22512218            break;
    22522219    }
     
    22982265    raidrec = &raidlist->el[pos_in_raidlist];
    22992266    initialize_raidrec(raidrec);
    2300     strcpy(raidrec->OSSWAP(raid_device, volname),
    2301            OSSWAP(device, basename(device)));
     2267    strcpy(raidrec->OSSWAP(raid_device, volname), OSSWAP(device, basename(device)));
    23022268#ifndef __FreeBSD__
    23032269    choose_raid_level(raidrec);
     
    25492515                                                   char *new_dev)
    25502516{
    2551     /** buffers ********************************************************/
    2552     char tmp[MAX_STR_LEN];
    2553 
    25542517    /** int ************************************************************/
    25552518    int pos = 0;
     
    25622525    pos = which_raid_device_is_using_this_partition(raidlist, old_dev);
    25632526    if (pos < 0) {
    2564         sprintf(tmp, "No need to rejig %s in raidlist: it's not listed.",
    2565                 old_dev);
    2566         log_it(tmp);
     2527        log_it("No need to rejig %s in raidlist: it's not listed.", old_dev);
    25672528    } else {
    25682529        if ((j =
     
    25702531                                         OSSWAP(el[pos].data_disks, disks),
    25712532                                         old_dev)) >= 0) {
    2572             strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j].
    2573                    device, new_dev);
     2533            strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j].device, new_dev);
    25742534        } else
    25752535            if ((j =
     
    25782538                                                    spares),
    25792539                                             old_dev)) >= 0) {
    2580             strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j].
    2581                    device, new_dev);
     2540            strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j].device, new_dev);
    25822541        }
    25832542#ifndef __FreeBSD__
     
    25962555#endif
    25972556        else {
    2598             sprintf(tmp,
    2599                     "%s is supposed to be listed in this raid dev but it's not...",
    2600                     old_dev);
    2601             log_it(tmp);
     2557            log_it("%s is supposed to be listed in this raid dev but it's not...", old_dev);
    26022558        }
    26032559    }
     
    26712627    /** buffers **********************************************************/
    26722628    void *keylist[ARBITRARY_MAXIMUM];
    2673     char *tmp;
    2674     char *help_text;
    2675     char *title_of_window;
    2676     char *sz_res;
    2677     char *header_text;
     2629    char *tmp = NULL;
     2630    char *help_text = NULL;
     2631    char *title_of_window = NULL;
     2632    char sz_res[MAX_STR_LEN];
     2633    char *header_text = NULL;
     2634    char *p = NULL;
    26782635
    26792636  /** int **************************************************************/
     
    26882645
    26892646    log_it("malloc'ing");
    2690     malloc_string(tmp);
    2691     malloc_string(help_text);
    2692     malloc_string(title_of_window);
    2693     malloc_string(sz_res);
    2694     malloc_string(header_text);
    2695     if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) {
    2696         fatal_error("Cannot malloc space for raidrec");
    2697     }
    2698     if (!(bkp_disklist = malloc(sizeof(struct list_of_disks)))) {
    2699         fatal_error("Cannot malloc space for disklist");
    2700     }
    2701     if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself)))) {
    2702         fatal_error("Cannot malloc space for raidlist");
    2703     }
    2704     if (!
    2705         (unallocated_raid_partitions =
    2706          malloc(sizeof(struct mountlist_itself)))) {
    2707         fatal_error("Cannot malloc space for unallocated_raid_partitions");
    2708     }
    2709 
    2710     memcpy((void *) bkp_raidlist, (void *) raidlist,
    2711            sizeof(struct raidlist_itself));
    2712     memcpy((void *) bkp_raidrec, (void *) raidrec,
    2713            sizeof(struct raid_device_record));
    2714     memcpy((void *) bkp_disklist, (void *) disklist,
    2715            sizeof(struct list_of_disks));
     2647    bkp_raidrec = mr_malloc(sizeof(struct raid_device_record));
     2648    bkp_disklist = mr_malloc(sizeof(struct list_of_disks));
     2649    bkp_raidlist = mr_malloc(sizeof(struct raidlist_itself));
     2650    unallocated_raid_partitions = mr_malloc(sizeof(struct mountlist_itself));
     2651
     2652    memcpy((void *) bkp_raidlist, (void *) raidlist, sizeof(struct raidlist_itself));
     2653    memcpy((void *) bkp_raidrec, (void *) raidrec, sizeof(struct raid_device_record));
     2654    memcpy((void *) bkp_disklist, (void *) disklist, sizeof(struct list_of_disks));
    27162655
    27172656    log_it("Post-malloc");
    2718     strcpy(help_text,
    2719            "   Edit this RAID device's list of partitions. Choose OK or Cancel when done.");
    2720     sprintf(header_text, "%-24s    %s", "Device", "Index");
    2721     sprintf(title_of_window, "%s contains...", raidrec->raid_device);
     2657    mr_asprintf(help_text, "   Edit this RAID device's list of partitions. Choose OK or Cancel when done.");
     2658    mr_asprintf(header_text, "%-24s    %s", "Device", "Index");
     2659    mr_asprintf(title_of_window, "%s contains...", raidrec->raid_device);
    27222660    newtPushHelpLine(help_text);
    27232661    for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) {
     
    27742712                    redraw_disklist(disklist, keylist, partitionsListbox);
    27752713                } else {
    2776                     sprintf(tmp, "%s's index is %d. What should it be?",
    2777                             raidrec->raid_device,
    2778                             disklist->el[currline].index);
     2714                    mr_asprintf(tmp, "%s's index is %d. What should it be?", raidrec->raid_device, disklist->el[currline].index);
    27792715                    sprintf(sz_res, "%d", disklist->el[currline].index);
    27802716                    if (popup_and_get_string("Set index", tmp, sz_res, 10)) {
    27812717                        disklist->el[currline].index = atoi(sz_res);
    27822718                    }
     2719                    mr_free(tmp);
     2720
    27832721                    redraw_disklist(disklist, keylist, partitionsListbox);
    27842722                }
     
    27892727    }
    27902728    newtPopHelpLine();
     2729    mr_free(help_text);
     2730    mr_free(header_text);
     2731    mr_free(title_of_window);
     2732
    27912733    if (b_res == bCancel) {
    2792         memcpy((void *) raidlist, (void *) bkp_raidlist,
    2793                sizeof(struct raidlist_itself));
    2794         memcpy((void *) raidrec, (void *) bkp_raidrec,
    2795                sizeof(struct raid_device_record));
    2796         memcpy((void *) disklist, (void *) bkp_disklist,
    2797                sizeof(struct list_of_disks));
    2798     }
    2799     paranoid_free(tmp);
    2800     paranoid_free(help_text);
    2801     paranoid_free(title_of_window);
     2734        memcpy((void *) raidlist, (void *) bkp_raidlist, sizeof(struct raidlist_itself));
     2735        memcpy((void *) raidrec, (void *) bkp_raidrec, sizeof(struct raid_device_record));
     2736        memcpy((void *) disklist, (void *) bkp_disklist, sizeof(struct list_of_disks));
     2737    }
    28022738    paranoid_free(sz_res);
    2803     paranoid_free(header_text);
    2804     paranoid_free(bkp_raidrec);
    2805     paranoid_free(bkp_disklist);
    2806     paranoid_free(bkp_raidlist);
    2807     paranoid_free(unallocated_raid_partitions);
     2739    mr_free(bkp_raidrec);
     2740    mr_free(bkp_disklist);
     2741    mr_free(bkp_raidlist);
     2742    mr_free(unallocated_raid_partitions);
    28082743}
    28092744#endif
     
    28212756  /** char *************************************************************/
    28222757    char output = '\0';
    2823     char tmp[MAX_STR_LEN];
     2758    char *tmp = NULL;
    28242759
    28252760  /** newt *************************************************************/
     
    28332768
    28342769    if (g_text_mode) {
    2835         for (output = 'z'; !strchr("AICE", output); output = tmp[0]) {
    2836             printf
    2837                 ("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> ");
    2838             if (fgets(tmp, MAX_STR_LEN - 1, stdin)) {
    2839                 // FIXME
    2840             }
     2770        while (!strchr("AICE", output)) {
     2771            printf("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> ");
     2772            mr_getline(tmp, stdin);
     2773            output = tmp[0];
     2774            mr_free(tmp);
    28412775        }
    28422776        return (output);
    28432777    }
    28442778
    2845     newtPushHelpLine
    2846         ("   Do you want to 'nuke' your system, restore interactively, or just compare?");
     2779    newtPushHelpLine("   Do you want to 'nuke' your system, restore interactively, or just compare?");
    28472780    newtOpenWindow(24, 3, 32, 17, "How should I restore?");
    28482781    b1 = newtButton(7, 1, "Automatically");
  • branches/3.2/mondo/src/mondorestore/mondo-rstr-tools.c

    r3185 r3193  
    77#include "my-stuff.h"
    88#include "mr_mem.h"
     9#include "mr_str.h"
    910#include "../common/mondostructures.h"
    1011#include "../common/libmondo.h"
     
    120121* @ingroup restoreUtilityGroup
    121122*/
    122 void ask_about_these_imagedevs(char *infname, char *outfname)
    123 {
     123void ask_about_these_imagedevs(char *infname, char *outfname) {
     124
    124125FILE *fin;
    125126FILE *fout;
    126 /************************************************************************
    127 * allocate memory regions. test and set  -sab 16 feb 2003              *
    128 ************************************************************************/
    129 char *incoming_ptr;
    130 char *question_ptr;
    131 char *q;
    132 
    133 char incoming[MAX_STR_LEN] = "\0";
    134 char question[MAX_STR_LEN];
     127char *incoming = NULL;
     128char *question = NULL;
    135129
    136130assert_string_is_neither_NULL_nor_zerolength(infname);
    137131assert_string_is_neither_NULL_nor_zerolength(outfname);
    138132
    139 incoming_ptr = malloc(sizeof(incoming));
    140 if (incoming_ptr == NULL) {
    141     fprintf(stderr, "Out of Memory\n");
    142     exit(EXIT_FAILURE);
    143 }
    144 
    145 question_ptr = malloc(sizeof(question));
    146 if (question_ptr == NULL) {
    147     fprintf(stderr, "Out of Memory\n");
    148     exit(EXIT_FAILURE);
    149 }
    150 
    151 memset(incoming_ptr, '\0', sizeof(incoming));
    152 memset(question_ptr, '\0', sizeof(question));
    153 
    154 
    155 
    156133if (!(fin = fopen(infname, "r"))) {
    157134    fatal_error("Cannot openin infname");
     
    160137    fatal_error("Cannot openin outfname");
    161138}
    162 for (q = fgets(incoming_ptr, MAX_STR_LEN, fin); !feof(fin) && (q != NULL); q = fgets(incoming_ptr, MAX_STR_LEN, fin)) {
    163     strip_spaces(incoming_ptr);
     139for (mr_getline(incoming, fin); !feof(fin) && (incoming != NULL); mr_getline(incoming, fin)) {
     140    mr_strip_spaces(incoming);
    164141
    165142    if (incoming[0] == '\0') {
     143        mr_free(incoming);
    166144        continue;
    167145    }
    168146
    169     sprintf(question_ptr, "Should I restore the image of %s ?", incoming_ptr);
    170 
    171     if (ask_me_yes_or_no(question_ptr)) {
    172         fprintf(fout, "%s\n", incoming_ptr);
    173     }
    174 }
    175 
    176 /*** free memory ***********/
    177 paranoid_free(incoming_ptr);
    178 incoming_ptr = NULL;
    179 paranoid_free(question_ptr);
    180 question_ptr = NULL;
    181 
    182 
     147    mr_asprintf(question, "Should I restore the image of %s ?", incoming);
     148   
     149    if (ask_me_yes_or_no(question)) {
     150        fprintf(fout, "%s\n", incoming);
     151    }
     152    mr_free(incoming);
     153}
     154mr_free(incoming);
     155mr_free(question);
    183156paranoid_fclose(fout);
    184157paranoid_fclose(fin);
     
    232205{
    233206
    234 /** needs malloc **/
    235 char *command;
    236 char *file;
    237 char *tmp;
     207char *command = NULL;
     208char *file = NULL;
     209char *tmp = NULL;
    238210int res;
    239211
    240 malloc_string(command);
    241 malloc_string(file);
    242 malloc_string(tmp);
    243212assert_string_is_neither_NULL_nor_zerolength(f);
    244213assert_string_is_neither_NULL_nor_zerolength(list_fname);
     
    246215
    247216if (strncmp(preamble, f, strlen(preamble)) == 0) {
    248 strcpy(file, f + strlen(preamble));
     217    mr_asprintf(file, "%s", f + strlen(preamble));
    249218} else {
    250 strcpy(file, f);
     219    mr_asprintf(file, "%s", f);
    251220}
    252221if (file[0] == '/' && file[1] == '/') {
    253 strcpy(tmp, file);
    254 strcpy(file, tmp + 1);
    255 }
    256 sprintf(tmp,
    257     "Checking to see if f=%s, file=%s, is in the list of biggiefiles",
    258     f, file);
    259 log_msg(2, tmp);
    260 sprintf(command, "grep -E '^%s$' %s", file, list_fname);
     222    tmp = file;
     223
     224    mr_asprintf(file, "%s", tmp + 1);
     225    mr_free(tmp);
     226}
     227log_msg(2, "Checking to see if f=%s, file=%s, is in the list of biggiefiles", f, file);
     228mr_asprintf(command, "grep -E '^%s$' %s", file, list_fname);
     229mr_free(file);
     230
    261231res = run_program_and_log_output(command, FALSE);
    262 paranoid_free(command);
    263 paranoid_free(file);
    264 paranoid_free(tmp);
     232mr_free(command);
    265233if (res) {
    266 return (FALSE);
     234    return (FALSE);
    267235} else {
    268 return (TRUE);
     236    return (TRUE);
    269237}
    270238}
     
    351319* @return 0 for success, nonzero for failure.
    352320*/
    353 int iso_fiddly_bits(bool nuke_me_please)
    354 {
     321int iso_fiddly_bits(bool nuke_me_please) {
     322
    355323char *mount_isodir_command = NULL;
    356 char *tmp, *command;
     324char *command = NULL;
    357325char *mds = NULL;
    358326int retval = 0, i;
    359327
    360 assert(bkpinfo != NULL);
    361 malloc_string(tmp);
    362 malloc_string(command);
    363328g_ISO_restore_mode = TRUE;
    364329read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
     
    370335    }
    371336    /* End patch */
    372     sprintf(command, "mkdir -p %s", bkpinfo->isodir);
     337    mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);
    373338    run_program_and_log_output(command, 5);
     339    mr_free(command);
    374340    log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
    375341}
     
    387353        mr_strcat(mount_isodir_command, " -t %s", g_isodir_format);
    388354    }
     355
    389356    mr_strcat(mount_isodir_command, " -o ro %s", bkpinfo->isodir);
    390     run_program_and_log_output("df -m", FALSE);
    391     sprintf(tmp,
    392         "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
    393         mount_isodir_command);
    394     log_msg(1, tmp);
     357    run_program_and_log_output("df -m -P", FALSE);
     358    log_msg(1, "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", mount_isodir_command);
    395359    if (run_program_and_log_output(mount_isodir_command, FALSE)) {
    396360        popup_and_OK
     
    407371i = what_number_cd_is_this();   /* has the side-effect of calling mount_media() */
    408372mds = media_descriptor_string(bkpinfo->backup_media_type);
    409 sprintf(tmp, "%s #%d has been mounted via loopback mount", mds, i);
    410373mr_free(mds);
    411374
    412 log_msg(1, tmp);
     375log_msg(1, "%s #%d has been mounted via loopback mount", mds, i);
    413376if (i < 0) {
    414 popup_and_OK
    415     ("Cannot find ISO images in the directory you specified.");
    416 retval = 1;
    417 }
    418 log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
    419     bkpinfo->isodir);
    420 paranoid_free(tmp);
    421 paranoid_free(command);
     377    popup_and_OK("Cannot find ISO images in the directory you specified.");
     378    retval = 1;
     379}
     380log_msg(2, "bkpinfo->isodir is now %s", bkpinfo->isodir);
    422381return (retval);
    423382}
     
    451410
    452411/** malloc **/
    453 char *tmp, *command, *mountdir, *mountpoint;
     412char *tmp = NULL;
     413char *command = NULL;
     414char *mountdir = NULL;
     415char *mountpoint = NULL;
    454416char *additional_parameters = NULL;
    455417
     
    457419assert_string_is_neither_NULL_nor_zerolength(mpt);
    458420assert(format != NULL);
    459 malloc_string(tmp);
    460 malloc_string(command);
    461 malloc_string(mountdir);
    462 malloc_string(mountpoint);
    463421
    464422    if (!strcmp(mpt, "/1")) {
    465         strcpy(mountpoint, "/");
     423        mr_asprintf(mountpoint, "/");
    466424        log_msg(3, "Mommm! SME is being a dildo!");
    467425    } else {
    468         strcpy(mountpoint, mpt);
     426        mr_asprintf(mountpoint, "%s", mpt);
    469427    }
    470428
     
    475433        return (0);
    476434    }
    477     sprintf(tmp, "Mounting device %s   ", device);
     435    mr_asprintf(tmp, "Mounting device %s   ", device);
    478436    log_msg(1, tmp);
    479437    /* Deal with additional params only if not /proc or /sys */
     
    494452
    495453    if (!strcmp(mountpoint, "swap")) {
    496         sprintf(command, "swapon %s", device);
     454        mr_asprintf(command, "swapon %s", device);
     455        mr_asprintf(mountdir, "swap");
    497456    } else {
    498457        if (!strcmp(mountpoint, "/")) {
    499             strcpy(mountdir, MNT_RESTORING);
     458            mr_asprintf(mountdir, "%s", MNT_RESTORING);
    500459        } else {
    501             sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
    502         }
    503         sprintf(command, "mkdir -p %s", mountdir);
     460            mr_asprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
     461        }
     462        mr_asprintf(command, "mkdir -p %s", mountdir);
    504463        run_program_and_log_output(command, FALSE);
    505         sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device,
    506                 additional_parameters, mountdir, MONDO_LOGFILE);
     464        mr_free(command);
     465
     466        mr_asprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, additional_parameters, mountdir, MONDO_LOGFILE);
    507467        log_msg(2, "command='%s'", command);
    508468    }
    509     paranoid_free(additional_parameters);
     469    mr_free(additional_parameters);
    510470
    511471    res = run_program_and_log_output(command, TRUE);
    512472    if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
    513473        log_msg(1, "Re-trying without the fancy extra parameters");
    514         sprintf(command, "mount -t %s %s %s 2>> %s", format, device,
    515             mountdir, MONDO_LOGFILE);
     474        mr_free(command);
     475        mr_asprintf(command, "mount -t %s %s %s 2>> %s", format, device, mountdir, MONDO_LOGFILE);
    516476        res = run_program_and_log_output(command, TRUE);
    517477    }
    518478    if (res) {
    519         log_msg(1, "Unable to mount device %s (type %s) at %s", device,
    520                 format, mountdir);
     479        log_msg(1, "Unable to mount device %s (type %s) at %s", device, format, mountdir);
    521480        log_msg(1, "command was '%s'", command);
    522481        if (!strcmp(mountpoint, "swap")) {
     
    524483        } else {
    525484            log_msg(2, "Retrying w/o the '-t' switch");
    526             sprintf(command, "mount %s %s 2>> %s", device, mountdir,
    527                 MONDO_LOGFILE);
     485            mr_free(command);
     486            mr_asprintf(command, "mount %s %s 2>> %s", device, mountdir, MONDO_LOGFILE);
    528487            log_msg(2, "2nd command = '%s'", command);
    529488            res = run_program_and_log_output(command, TRUE);
     
    543502    }
    544503
    545 paranoid_free(tmp);
    546 paranoid_free(command);
    547 paranoid_free(mountdir);
    548 paranoid_free(mountpoint);
    549 
    550     return (res);
     504mr_free(tmp);
     505mr_free(command);
     506mr_free(mountdir);
     507mr_free(mountpoint);
     508
     509return (res);
    551510}
    552511/**************************************************************************
     
    561520 * @return The number of errors encountered (0 for success).
    562521 */
    563 int mount_all_devices(struct mountlist_itself
    564                       *p_external_copy_of_mountlist, bool writeable)
     522int mount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist, bool writeable)
    565523{
    566524int retval = 0, lino, res;
    567 char *tmp;
     525char *tmp = NULL;
    568526char *these_failed = NULL;
    569 char *format;
    570527struct mountlist_itself *mountlist = NULL;
    571 
    572 malloc_string(tmp);
    573 malloc_string(format);
    574528
    575529assert(p_external_copy_of_mountlist != NULL);
     
    581535
    582536    mvaddstr_and_log_it(g_currentY, 0, "Mounting devices         ");
    583     open_progress_form("Mounting devices",
    584                "I am now mounting all the drives.",
    585                "This should not take long.",
    586                "", mountlist->entries);
     537    open_progress_form("Mounting devices", "I am now mounting all the drives.", "This should not take long.", "", mountlist->entries);
    587538
    588539    mr_asprintf(these_failed, "");
    589540    for (lino = 0; lino < mountlist->entries; lino++) {
    590541        if (!strcmp(mountlist->el[lino].device, "/proc")) {
    591             log_msg(1,
    592                 "Again with the /proc - why is this in your mountlist?");
     542            log_msg(1, "Again with the /proc - why is this in your mountlist?");
    593543        } else if (is_this_device_mounted(mountlist->el[lino].device)) {
    594             sprintf(tmp, "%s is already mounted",
    595                 mountlist->el[lino].device);
    596             log_to_screen(tmp);
     544            log_to_screen("%s is already mounted", mountlist->el[lino].device);
    597545        } else if (strcmp(mountlist->el[lino].mountpoint, "none")
    598546           && strcmp(mountlist->el[lino].mountpoint, "lvm")
    599547           && strcmp(mountlist->el[lino].mountpoint, "raid")
    600548           && strcmp(mountlist->el[lino].mountpoint, "image")) {
    601             sprintf(tmp, "Mounting %s", mountlist->el[lino].device);
     549            mr_asprintf(tmp, "Mounting %s", mountlist->el[lino].device);
    602550            update_progress_form(tmp);
    603             strcpy(format, mountlist->el[lino].format);
    604             res = mount_device(mountlist->el[lino].device,
    605                        mountlist->el[lino].mountpoint,
    606                        format, writeable);
     551            mr_free(tmp);
     552            res = mount_device(mountlist->el[lino].device, mountlist->el[lino].mountpoint, mountlist->el[lino].format, writeable);
    607553            retval += res;
    608554            if (res) {
     
    615561    if (retval) {
    616562        if (g_partition_table_locked_up > 0) {
    617             log_to_screen
    618                 ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
    619             log_to_screen
    620                 ("lock up the partition table. You might have to reboot and use Interactive Mode to");
    621             log_to_screen
    622                 ("format and restore *without* partitioning first. Sorry for the inconvenience.");
    623         }
    624         sprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed);
     563            log_to_screen("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
     564            log_to_screen("lock up the partition table. You might have to reboot and use Interactive Mode to");
     565            log_to_screen("format and restore *without* partitioning first. Sorry for the inconvenience.");
     566        }
     567        mr_asprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed);
    625568
    626569        if (!ask_me_yes_or_no(tmp)) {
    627570            retval = 0;
    628             log_to_screen
    629                 ("Continuing, although some device(s) failed to be mounted");
     571            log_to_screen("Continuing, although some device(s) failed to be mounted");
    630572            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    631573        } else {
    632574            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    633             log_to_screen
    634         ("Unable to mount some or all of your partitions.");
    635         }
     575            log_to_screen("Unable to mount some or all of your partitions.");
     576        }
     577        mr_free(tmp);
    636578    } else {
    637579        log_to_screen("All partitions were mounted OK.");
     
    643585    (void)mount_device("/proc","/proc","proc",TRUE);
    644586    (void)mount_device("/sys","/sys","sysfs",TRUE);
    645     run_program_and_log_output("df -m", 3);
     587    run_program_and_log_output("df -m -P", 3);
    646588    paranoid_free(mountlist);
    647     paranoid_free(tmp);
    648     paranoid_free(format);
    649589    return (retval);
    650590}
     
    652592*END_MOUNT_ALL_DEVICES                                                   *
    653593**************************************************************************/
    654 
    655 
    656594
    657595
     
    700638{
    701639/** add mallocs **/
    702 char *value = NULL;
     640char value[MAX_STR_LEN];
    703641char *tmp = NULL;
     642char *tmp1 = NULL;
    704643char *envtmp1 = NULL;
    705644char *envtmp2 = NULL;
    706645char *command = NULL;
    707 char *iso_mnt = NULL;
    708 char *iso_path = NULL;
     646char iso_mnt[MAX_STR_LEN];
     647char iso_path[MAX_STR_LEN];
    709648char *old_isodir = NULL;
    710 char cfg_file[100];
     649char *cfg_file = NULL;
    711650t_bkptype media_specified_by_user;
    712651
    713 malloc_string(command);
    714 malloc_string(iso_mnt);
    715 malloc_string(iso_path);
    716 malloc_string(old_isodir);
    717 malloc_string(value);
    718 malloc_string(tmp);
    719652//  assert_string_is_neither_NULL_nor_zerolength(cfg_file);
    720653assert(bkpinfo != NULL);
     654assert(cfgf != NULL);
    721655log_it("Entering read_cfg_file_into_bkpinfo");
    722656
     
    730664
    731665if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
    732 if (!strcmp(value, "cdstream")) {
    733     bkpinfo->backup_media_type = cdstream;
    734 } else if (!strcmp(value, "cdr")) {
    735     bkpinfo->backup_media_type = cdr;
    736 } else if (!strcmp(value, "cdrw")) {
    737     bkpinfo->backup_media_type = cdrw;
    738 } else if (!strcmp(value, "dvd")) {
    739     bkpinfo->backup_media_type = dvd;
    740 } else if (!strcmp(value, "usb")) {
    741     bkpinfo->backup_media_type = usb;
    742     bkpinfo->please_dont_eject = TRUE;
    743 } else if (!strcmp(value, "iso")) {
    744     bkpinfo->backup_media_type = iso;
    745     if (am_I_in_disaster_recovery_mode()) {
    746         /* Check to see if CD is already mounted before mounting it... */
    747         if (!is_this_device_mounted("/dev/cdrom")) {
    748             log_msg(2, "NB: CDROM device not mounted, mounting...");
    749             run_program_and_log_output("mount /dev/cdrom " MNT_CDROM, 1);
    750         }
    751         if (does_file_exist(MNT_CDROM "/archives/filelist.0")) {
    752             bkpinfo->backup_media_type = cdr;
    753             run_program_and_log_output("umount -d " MNT_CDROM, 1);
    754             log_it("Re-jigging configuration AGAIN. CD-R, not ISO.");
    755         }
    756     }
    757     if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
    758         strcpy(bkpinfo->prefix,value);
     666    if (!strcmp(value, "cdstream")) {
     667        bkpinfo->backup_media_type = cdstream;
     668    } else if (!strcmp(value, "cdr")) {
     669        bkpinfo->backup_media_type = cdr;
     670    } else if (!strcmp(value, "cdrw")) {
     671        bkpinfo->backup_media_type = cdrw;
     672    } else if (!strcmp(value, "dvd")) {
     673        bkpinfo->backup_media_type = dvd;
     674    } else if (!strcmp(value, "usb")) {
     675        bkpinfo->backup_media_type = usb;
     676        bkpinfo->please_dont_eject = TRUE;
     677    } else if (!strcmp(value, "iso")) {
     678        bkpinfo->backup_media_type = iso;
     679        if (am_I_in_disaster_recovery_mode()) {
     680            /* Check to see if CD is already mounted before mounting it... */
     681            if (!is_this_device_mounted("/dev/cdrom")) {
     682                log_msg(2, "NB: CDROM device not mounted, mounting...");
     683                run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1);
     684            }
     685            if (does_file_exist(MNT_CDROM"/archives/filelist.0")) {
     686                bkpinfo->backup_media_type = cdr;
     687                run_program_and_log_output("umount -d "MNT_CDROM, 1);
     688                log_it("Re-jigging configuration AGAIN. CD-R, not ISO.");
     689            }
     690        }
     691        if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
     692            strcpy(bkpinfo->prefix,value);
     693        } else {
     694            strcpy(bkpinfo->prefix,STD_PREFIX);
     695        }
     696        log_it("Setting Prefix to %s", bkpinfo->prefix);
     697    } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) {
     698        /* Stay compatible with previous versions by allowing nfs as an entry here */
     699        bkpinfo->backup_media_type = netfs;
     700        bkpinfo->please_dont_eject = TRUE;
     701        if (read_cfg_var(cfg_file, "netfs-proto", value) == 0) {
     702            mr_asprintf(bkpinfo->netfs_proto,"%s", value);
     703        } else {
     704            /* For compatibility, force protocol in old nfs case to be transparent */
     705            mr_asprintf(bkpinfo->netfs_proto, "nfs");
     706        }
     707        if (read_cfg_var(cfg_file, "netfs-server-user", value) == 0) {
     708            mr_asprintf(bkpinfo->netfs_user,"%s", value);
     709        }
     710        if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
     711                strcpy(bkpinfo->prefix,value);
     712        } else {
     713                strcpy(bkpinfo->prefix,STD_PREFIX);
     714        }
     715        if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "pxe")) {
     716            /* We need to override prefix value in PXE mode as it's
     717            * already done in start-netfs */
     718            envtmp1 = getenv("imgname");
     719            if (envtmp1 == NULL) {
     720                fatal_error("no imgname variable in environment");
     721            }
     722            strcpy(bkpinfo->prefix,envtmp1);
     723        }   
     724    } else if (!strcmp(value, "tape")) {
     725        bkpinfo->backup_media_type = tape;
     726    } else if (!strcmp(value, "udev")) {
     727        bkpinfo->backup_media_type = udev;
    759728    } else {
    760         strcpy(bkpinfo->prefix,STD_PREFIX);
    761     }
    762     log_it("Setting Prefix to %s", bkpinfo->prefix);
    763 } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) {
    764     /* Stay compatible with previous versions by allowing nfs as an entry here */
    765     bkpinfo->backup_media_type = netfs;
    766     bkpinfo->please_dont_eject = TRUE;
    767     if (read_cfg_var(cfg_file, "netfs-proto", value) == 0) {
    768         mr_asprintf(bkpinfo->netfs_proto,"%s", value);
    769     } else {
    770         /* For compatibility, force protocol in old nfs case to be transparent */
    771         mr_asprintf(bkpinfo->netfs_proto, "nfs");
    772     }
    773     if (read_cfg_var(cfg_file, "netfs-server-user", value) == 0) {
    774         mr_asprintf(bkpinfo->netfs_user,"%s", value);
    775     }
    776     if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
    777             strcpy(bkpinfo->prefix,value);
    778     } else {
    779             strcpy(bkpinfo->prefix,STD_PREFIX);
    780     }
    781     if (strstr(call_program_and_get_last_line_of_output
    782        ("cat /proc/cmdline"), "pxe")) {
    783         /* We need to override prefix value in PXE mode as it's
    784         * already done in start-netfs */
    785         envtmp1 = getenv("imgname");
    786         if (envtmp1 == NULL) {
    787             fatal_error("no imgname variable in environment");
    788         }
    789         strcpy(bkpinfo->prefix,envtmp1);
    790     }
    791 
    792 } else if (!strcmp(value, "tape")) {
    793     bkpinfo->backup_media_type = tape;
    794 } else if (!strcmp(value, "udev")) {
    795     bkpinfo->backup_media_type = udev;
     729        fatal_error("UNKNOWN bkp-media-type");
     730    }
    796731} else {
    797     fatal_error("UNKNOWN bkp-media-type");
    798 }
    799 } else {
    800 fatal_error("backup-media-type not specified!");
    801 }
     732    fatal_error("backup-media-type not specified!");
     733}
     734
    802735if (bkpinfo->disaster_recovery) {
    803736    if (bkpinfo->backup_media_type == cdstream) {
     
    814747        }
    815748        sprintf(bkpinfo->media_device, "%s1", value);
    816         sprintf(tmp, "Backup medium is USB --- dev=%s", bkpinfo->media_device);
    817         log_msg(2, tmp);
    818     } else if (bkpinfo->backup_media_type == tape
    819             || bkpinfo->backup_media_type == udev) {
     749        log_msg(2, "Backup medium is USB --- dev=%s", bkpinfo->media_device);
     750    } else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
    820751        if (read_cfg_var(cfg_file, "media-dev", value)) {
    821752            fatal_error("Cannot get tape device name from cfg file");
     
    824755        read_cfg_var(cfg_file, "media-size", value);
    825756        bkpinfo->media_size = atol(value);
    826         sprintf(tmp, "Backup medium is TAPE --- dev=%s",
    827                 bkpinfo->media_device);
    828         log_msg(2, tmp);
     757        log_msg(2, "Backup medium is TAPE --- dev=%s", bkpinfo->media_device);
    829758    } else {
    830759        strcpy(bkpinfo->media_device, "/dev/cdrom");    /* we don't really need this var */
     
    833762    }
    834763} else {
    835     log_msg(2,
    836         "Not in Disaster Recovery Mode. No need to derive device name from config file.");
     764    log_msg(2, "Not in Disaster Recovery Mode. No need to derive device name from config file.");
    837765}
    838766
     
    867795
    868796if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
    869 bkpinfo->internal_tape_block_size = atol(value);
    870 log_msg(1, "Internal tape block size has been custom-set to %ld",
    871         bkpinfo->internal_tape_block_size);
     797    bkpinfo->internal_tape_block_size = atol(value);
    872798} else {
    873 bkpinfo->internal_tape_block_size =
    874     DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    875 log_msg(1, "Internal tape block size = default (%ld)",
    876         DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
     799    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
     800}
     801log_msg(1, "Internal tape block size set to %ld", bkpinfo->internal_tape_block_size);
     802
     803read_cfg_var(cfg_file, "use-lzma", value);
     804if (strstr(value, "yes")) {
     805    bkpinfo->use_lzma = TRUE;
     806    bkpinfo->use_lzo = FALSE;
     807    bkpinfo->use_gzip = FALSE;
     808    strcpy(bkpinfo->zip_exe, "lzma");
     809    strcpy(bkpinfo->zip_suffix, "lzma");
    877810}
    878811
    879812read_cfg_var(cfg_file, "use-lzo", value);
    880813if (strstr(value, "yes")) {
    881 bkpinfo->use_lzo = TRUE;
    882 bkpinfo->use_gzip = FALSE;
    883 strcpy(bkpinfo->zip_exe, "lzop");
    884 strcpy(bkpinfo->zip_suffix, "lzo");
    885 } else {
     814    bkpinfo->use_lzma = FALSE;
     815    bkpinfo->use_lzo = TRUE;
     816    bkpinfo->use_gzip = FALSE;
     817    strcpy(bkpinfo->zip_exe, "lzop");
     818    strcpy(bkpinfo->zip_suffix, "lzo");
     819}
     820
    886821read_cfg_var(cfg_file, "use-gzip", value);
    887822if (strstr(value, "yes")) {
     823    bkpinfo->use_lzma = FALSE;
    888824    bkpinfo->use_lzo = FALSE;
    889825    bkpinfo->use_gzip = TRUE;
    890826    strcpy(bkpinfo->zip_exe, "gzip");
    891827    strcpy(bkpinfo->zip_suffix, "gz");
    892 } else {
    893     read_cfg_var(cfg_file, "use-comp", value);
    894     if (strstr(value, "yes")) {
    895         bkpinfo->use_lzo = FALSE;
    896         bkpinfo->use_gzip = FALSE;
    897         strcpy(bkpinfo->zip_exe, "bzip2");
    898         strcpy(bkpinfo->zip_suffix, "bz2");
    899     } else {
    900         bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
    901     }
    902 }
     828}
     829
     830read_cfg_var(cfg_file, "use-comp", value);
     831if (strstr(value, "yes")) {
     832    bkpinfo->use_lzma = FALSE;
     833    bkpinfo->use_lzo = FALSE;
     834    bkpinfo->use_gzip = FALSE;
     835    strcpy(bkpinfo->zip_exe, "bzip2");
     836    strcpy(bkpinfo->zip_suffix, "bz2");
    903837}
    904838
     
    906840read_cfg_var(cfg_file, "differential", value);
    907841if (!strcmp(value, "yes") || !strcmp(value, "1")) {
    908 bkpinfo->differential = TRUE;
     842    bkpinfo->differential = TRUE;
    909843}
    910844log_msg(2, "differential var = '%s'", value);
    911845if (bkpinfo->differential) {
    912 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
     846    log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
    913847} else {
    914 log_msg(2, "This is a regular (full) backup");
    915 }
    916 
    917 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);
    918 if (tmp[0] || strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "donteject")) {
     848    log_msg(2, "This is a regular (full) backup");
     849}
     850
     851read_cfg_var(g_mondo_cfg_file, "please-dont-eject", value);
     852if (value[0] || strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "donteject")) {
    919853    bkpinfo->please_dont_eject = TRUE;
    920854    log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
     
    923857if (bkpinfo->backup_media_type == netfs) {
    924858    if (!cfgf) {
    925         log_msg(2, "netfs_mount remains %s", bkpinfo->netfs_mount);
    926         log_msg(2, "netfs_remote_dir remains %s",
    927                 bkpinfo->netfs_remote_dir);
    928         log_msg(2,
    929                 "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
     859        if (bkpinfo->netfs_mount) {
     860            log_msg(2, "netfs_mount remains %s", bkpinfo->netfs_mount);
     861        }
     862        if (bkpinfo->netfs_remote_dir) {
     863            log_msg(2, "netfs_remote_dir remains %s", bkpinfo->netfs_remote_dir);
     864        }
     865        log_msg(2, "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
    930866    } else {
    931         read_cfg_var(g_mondo_cfg_file, "netfs-server-mount",
    932                     bkpinfo->netfs_mount);
    933         read_cfg_var(g_mondo_cfg_file, "netfs-server-path",
    934                     bkpinfo->netfs_remote_dir);
    935         log_msg(2, "netfs_mount is %s", bkpinfo->netfs_mount);
    936         log_msg(2, "netfs_proto is %s", bkpinfo->netfs_proto);
    937         if (bkpinfo->netfs_user) {
     867        read_cfg_var(g_mondo_cfg_file, "netfs-server-mount", value);
     868        mr_free(bkpinfo->netfs_mount);
     869        mr_asprintf(bkpinfo->netfs_mount, "%s", value);
     870
     871        read_cfg_var(g_mondo_cfg_file, "netfs-server-path", value);
     872        mr_free(bkpinfo->netfs_remote_dir);
     873        mr_asprintf(bkpinfo->netfs_remote_dir, "%s", value);
     874
     875        if (bkpinfo->netfs_mount != NULL) {
     876            log_msg(2, "netfs_mount is %s", bkpinfo->netfs_mount);
     877        }
     878        if (bkpinfo->netfs_remote_dir != NULL) {
     879            log_msg(2, "netfs_remote_dir is %s", bkpinfo->netfs_remote_dir);
     880        }
     881        if (bkpinfo->netfs_proto != NULL) {
     882            log_msg(2, "netfs_proto is %s", bkpinfo->netfs_proto);
     883        }
     884        if (bkpinfo->netfs_user != NULL) {
    938885            log_msg(2, "netfs_user is %s", bkpinfo->netfs_user);
    939886        }
    940         log_msg(2, "netfs_remote_dir is %s", bkpinfo->netfs_remote_dir);
    941     }
    942     if (strstr(call_program_and_get_last_line_of_output
    943         ("cat /proc/cmdline"), "pxe")) {
     887    }
     888    if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "pxe")) {
    944889        /* We need to override values in PXE mode as it's
    945890        * already done in start-netfs */
     
    952897            fatal_error("no dirimg variable in environment");
    953898        }
    954         strcpy(bkpinfo->netfs_mount,envtmp1);
    955         strcpy(bkpinfo->netfs_remote_dir,envtmp2);
     899        mr_free(bkpinfo->netfs_mount);
     900        mr_asprintf(bkpinfo->netfs_mount, "%s", envtmp1);
     901
     902        mr_free(bkpinfo->netfs_remote_dir);
     903        mr_asprintf(bkpinfo->netfs_remote_dir, "%s", envtmp2);
    956904    }
    957905} else if (bkpinfo->backup_media_type == iso) {
     
    960908    * isodir in disaster recovery mode
    961909    */
    962     strcpy(old_isodir, bkpinfo->isodir);
     910    mr_asprintf(old_isodir, "%s", bkpinfo->isodir);
    963911    read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
    964912    read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
     
    969917    if ((!bkpinfo->disaster_recovery) || (g_isodir_device[0] != '\0')) {
    970918        if (strcmp(old_isodir, bkpinfo->isodir)) {
    971             log_it
    972                 ("user nominated isodir %s differs from archive %s, keeping user's choice\n",
    973                 old_isodir, bkpinfo->isodir);
     919            log_it("user nominated isodir %s differs from archive, keeping user's choice: %s\n", bkpinfo->isodir, old_isodir );
    974920            strcpy(bkpinfo->isodir, old_isodir);
    975921        }
     
    982928
    983929    log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device);
     930
    984931    if (bkpinfo->disaster_recovery) {
    985932        if (is_this_device_mounted(g_isodir_device)) {
    986933            log_msg(2, "NB: isodir is already mounted");
    987934            /* Find out where it's mounted */
    988             sprintf(command, "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3", g_isodir_device);
     935            mr_asprintf(command, "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3", g_isodir_device);
    989936            log_it("command = %s", command);
    990             log_it("res of it = %s",
    991                 call_program_and_get_last_line_of_output(command));
    992             sprintf(iso_mnt, "%s",
    993                     call_program_and_get_last_line_of_output(command));
     937            log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
     938            mr_strcpy(iso_mnt, call_program_and_get_last_line_of_output(command));
     939            mr_free(command);
    994940        } else {
    995             sprintf(iso_mnt, "/tmp/isodir");
    996             sprintf(tmp, "mkdir -p %s", iso_mnt);
    997             run_program_and_log_output(tmp, 5);
    998             sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
    999             if (run_program_and_log_output(tmp, 3)) {
    1000                 log_msg(1,
    1001                         "Unable to mount isodir. Perhaps this is really a CD backup?");
     941            mr_asprintf(iso_mnt, "/tmp/isodir");
     942            mr_asprintf(tmp1, "mkdir -p %s", iso_mnt);
     943            run_program_and_log_output(tmp1, 5);
     944            mr_free(tmp1);
     945
     946            mr_asprintf(tmp1, "mount %s %s", g_isodir_device, iso_mnt);
     947            if (run_program_and_log_output(tmp1, 3)) {
     948                log_msg(1, "Unable to mount isodir. Perhaps this is really a CD backup?");
    1002949                bkpinfo->backup_media_type = cdr;
    1003950                strcpy(bkpinfo->media_device, "/dev/cdrom");    /* superfluous */
    1004951                bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
    1005952                if (mount_media()) {
    1006                     fatal_error
    1007                         ("Unable to mount isodir. Failed to mount CD-ROM as well.");
     953                    mr_free(tmp1);
     954                    fatal_error("Unable to mount isodir. Failed to mount CD-ROM as well.");
    1008955                } else {
    1009                     log_msg(1,
    1010                             "You backed up to disk, then burned some CDs.");
    1011                 }
    1012             }
     956                    log_msg(1, "You backed up to disk, then burned some CDs.");
     957                }
     958            }
     959            mr_free(tmp1);
    1013960        }
    1014961        /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */
    1015         /*  except when already done is iso_fiddly_bits */
     962        /*  except when already done in iso_fiddly_bits */
    1016963        if ((bkpinfo->backup_media_type == iso) && (g_isodir_device[0] == '\0')) {
    1017964            sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
     
    1027974            media_specified_by_user = bkpinfo->backup_media_type;
    1028975            get_cfg_file_from_archive();
    1029     /*
    1030         if (media_specified_by_user != cdr && media_specified_by_user == cdrw)
    1031             { g_restoring_live_from_cd = FALSE; }
    1032     */
    1033976        }
    1034977    }
     
    1037980g_backup_media_type = bkpinfo->backup_media_type;
    1038981paranoid_free(value);
    1039 paranoid_free(tmp);
    1040 paranoid_free(command);
    1041982paranoid_free(iso_mnt);
    1042983paranoid_free(iso_path);
    1043 paranoid_free(old_isodir);
    1044984return (0);
    1045985
     
    10681008struct s_node *filelist;
    10691009
    1070 /** add mallocs**/
    1071 char *command;
     1010char *command = NULL;
    10721011char *tmp;
    10731012char *q;
     
    10771016
    10781017assert(bkpinfo != NULL);
    1079 malloc_string(command);
    10801018malloc_string(tmp);
    10811019
     
    11051043    unlink(FILELIST_FULL_STUB);
    11061044    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    1107         sprintf(command,
    1108             "tar -b %ld -zxf %s ./%s ./%s ./%s ./%s ./%s",
    1109             bkpinfo->internal_tape_block_size,
    1110             bkpinfo->media_device,
    1111             MOUNTLIST_FNAME_STUB,
    1112             BIGGIELIST_TXT_STUB,
    1113             FILELIST_FULL_STUB,
    1114             IWANTMYLVM_STUB,
    1115             MONDO_CFG_FILE_STUB);
     1045        mr_asprintf(command, "tar -b %ld -zxf %s ./%s ./%s ./%s ./%s ./%s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
    11161046        log_msg(1, "tarcommand = %s", command);
    11171047        run_program_and_log_output(command, 1);
     1048        mr_free(command);
     1049
    11181050        if (!does_file_exist(FILELIST_FULL_STUB)) {
    11191051            /* Doing that allow us to remain compatible with pre-2.2.5 versions */
    11201052            log_msg(2, "pre-2.2.4 compatible mode on");
    1121             sprintf(command,
    1122                 "tar -b %ld -zxf %s %s %s %s %s %s",
    1123                 bkpinfo->internal_tape_block_size,
    1124                 bkpinfo->media_device,
    1125                 MOUNTLIST_FNAME_STUB,
    1126                 BIGGIELIST_TXT_STUB,
    1127                 FILELIST_FULL_STUB,
    1128                 IWANTMYLVM_STUB,
    1129                 MONDO_CFG_FILE_STUB);
     1053            mr_asprintf(command, "tar -b %ld -zxf %s %s %s %s %s %s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
    11301054            log_msg(1, "tarcommand = %s", command);
    11311055            run_program_and_log_output(command, 1);
     1056            mr_free(command);
    11321057        }
    11331058    } else {
    1134         log_msg(2,
    1135             "Calling insist_on_this_cd_number; bkpinfo->isodir=%s",
    1136             bkpinfo->isodir);
     1059        log_msg(2, "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir);
    11371060        insist_on_this_cd_number(1);
    11381061        log_msg(2, "Back from iotcn");
    11391062        run_program_and_log_output("mount", 1);
    1140         sprintf(command,
    1141             "tar -zxf %s/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s",
    1142             MNT_CDROM,
    1143             MOUNTLIST_FNAME_STUB,
    1144             BIGGIELIST_TXT_STUB,
    1145             FILELIST_FULL_STUB,
    1146             IWANTMYLVM_STUB,
    1147             MONDO_CFG_FILE_STUB);
     1063        mr_asprintf(command, "tar -zxf %s/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
    11481064
    11491065        log_msg(1, "tarcommand = %s", command);
    11501066        run_program_and_log_output(command, 1);
     1067        mr_free(command);
     1068
    11511069        if (!does_file_exist(FILELIST_FULL_STUB)) {
    11521070            /* Doing that allow us to remain compatible with pre-2.2.5 versions */
    11531071            log_msg(2, "pre-2.2.4 compatible mode on");
    1154             sprintf(command,
    1155                 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
    1156                 MNT_CDROM,
    1157                 MOUNTLIST_FNAME_STUB,
    1158                 BIGGIELIST_TXT_STUB,
    1159                 FILELIST_FULL_STUB,
    1160                 IWANTMYLVM_STUB,
    1161                 MONDO_CFG_FILE_STUB);
     1072            mr_asprintf(command, "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
    11621073
    11631074            log_msg(1, "tarcommand = %s", command);
    11641075            run_program_and_log_output(command, 1);
     1076            mr_free(command);
    11651077        }
    11661078        if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
    1167             fatal_error
    1168                 ("all.tar.gz did not include " BIGGIELIST_TXT_STUB);
     1079            fatal_error("all.tar.gz did not include " BIGGIELIST_TXT_STUB);
    11691080        }
    11701081        if (!does_file_exist(FILELIST_FULL_STUB)) {
    1171             fatal_error
    1172                 ("all.tar.gz did not include " FILELIST_FULL_STUB);
    1173         }
    1174     }
    1175     sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,
    1176         g_mondo_cfg_file);
     1082            fatal_error("all.tar.gz did not include " FILELIST_FULL_STUB);
     1083        }
     1084    }
     1085    mr_asprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file);
    11771086    run_program_and_log_output(command, FALSE);
    1178 
    1179     sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir,
    1180         BIGGIELIST_TXT_STUB, g_biggielist_txt);
     1087    mr_free(command);
     1088
     1089    mr_asprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt);
    11811090    log_msg(1, "command = %s", command);
    11821091    paranoid_system(command);
    1183     sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir,
    1184         FILELIST_FULL_STUB, g_filelist_full);
     1092    mr_free(command);
     1093
     1094    mr_asprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full);
    11851095    log_msg(1, "command = %s", command);
    11861096    paranoid_system(command);
     1097    mr_free(command);
    11871098    }
    11881099
     
    11941105    ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
    11951106    {
    1196         sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,
    1197             bkpinfo->tmpdir);
    1198     paranoid_system(command);
     1107        mr_asprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir);
     1108        paranoid_system(command);
     1109        mr_free(command);
    11991110    }
    12001111
     
    12091120        log_msg(1, "Warning - %s does not exist", g_filelist_full);
    12101121    }
    1211 //  popup_and_OK("Wonderful.");
    12121122
    12131123    log_msg(2, "Forking");
     
    12211131        log_to_screen("Pre-processing filelist");
    12221132        if (!does_file_exist(g_biggielist_txt)) {
    1223             sprintf(command, "echo -n > %s", g_biggielist_txt);
     1133            mr_asprintf(command, "echo -n > %s", g_biggielist_txt);
    12241134            paranoid_system(command);
    1225         }
    1226         sprintf(command, "grep -E '^/dev/.*' %s > %s",
    1227                 g_biggielist_txt, g_filelist_imagedevs);
     1135            mr_free(command);
     1136        }
     1137        mr_asprintf(command, "grep -E '^/dev/.*' %s > %s", g_biggielist_txt, g_filelist_imagedevs);
    12281138        paranoid_system(command);
     1139        mr_free(command);
    12291140        exit(0);
    12301141        break;
     
    12471158        while (q == NULL) {
    12481159            printf("Restore which directory? --> ");
    1249             q = fgets(tmp, sizeof(tmp), stdin);
    1250         }
    1251         toggle_path_selection(filelist, tmp, TRUE);
    1252         if (strlen(tmp) == 0) {
     1160            mr_getline(q, stdin);
     1161        }
     1162        toggle_path_selection(filelist, q, TRUE);
     1163        if (strlen(q) == 0) {
    12531164            res = 1;
    12541165        } else {
    12551166            res = 0;
    12561167        }
     1168        mr_free(q);
    12571169    } else {
    12581170        res = edit_filelist(filelist);
     
    12771189    }
    12781190
    1279     paranoid_free(command);
    12801191    paranoid_free(tmp);
    12811192    return (filelist);
     
    12981209int backup_crucial_file(char *path_root, char *filename)
    12991210{
    1300     char *tmp;
    1301     char *command;
     1211    char *tmp = NULL;
     1212    char *command = NULL;
    13021213    int res;
    13031214
    1304     malloc_string(tmp);
    1305     malloc_string(command);
    13061215    assert(path_root != NULL);
    13071216    assert_string_is_neither_NULL_nor_zerolength(filename);
    13081217
    1309     sprintf(tmp, "%s/%s", path_root, filename);
    1310     sprintf(command, "cp -f %s %s.pristine", tmp, tmp);
     1218    mr_asprintf(tmp, "%s/%s", path_root, filename);
     1219    mr_asprintf(command, "cp -f %s %s.pristine", tmp, tmp);
     1220    mr_free(tmp);
    13111221
    13121222    res = run_program_and_log_output(command, 5);
    1313     paranoid_free(tmp);
    1314     paranoid_free(command);
     1223    mr_free(command);
    13151224    return (res);
    13161225}
     
    13581267
    13591268  /** malloc *******/
    1360     char *device;
    1361     char *tmp = NULL;
    1362     char *name;
     1269    char *device = NULL;
     1270    char *name = NULL;
    13631271    char *cmd = NULL;
    13641272
     
    13851293    read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
    13861294    read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
    1387     mr_asprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name);
    1388     log_msg(2, tmp);
    1389     paranoid_free(tmp);
    1390     paranoid_system("sync");
     1295    log_msg(2, "run_boot_loader: device='%s', name='%s'", device, name);
     1296    sync();
    13911297
    13921298    offer_to_make_initrd();
     
    14081314        mr_asprintf(tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
    14091315        if (!system(tmp)) {
    1410             paranoid_free(tmp);
     1316            mr_free(tmp);
    14111317            mr_asprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
    14121318            res = run_program_and_log_output(tmp, 3);
    14131319        } else {
    1414             log_msg(1,
    1415                     "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
    1416         }
    1417         paranoid_free(tmp);
     1320            log_msg(1, "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
     1321        }
     1322        mr_free(tmp);
    14181323    }
    14191324#else
     
    14461351 * @note The returned string points to static storage that will be overwritten with each call.
    14471352 */
    1448 char *find_my_editor(void)
    1449 {
     1353char *find_my_editor(void) {
     1354
    14501355    static char output[MAX_STR_LEN];
    14511356    if (find_home_of_exe("pico")) {
     
    14761381{
    14771382  /** malloc **/
    1478     char *command;
    1479     char *boot_device;
    1480     char *rootdev;
    1481     char *rootdrive;
    1482     char *conffile;
    1483     char *tmp;
    1484     char *editor;
    1485 
     1383    char *command = NULL;
     1384    char *boot_device = NULL;
     1385    char *tmp = NULL;
     1386    char *editor = NULL;
     1387
     1388    bool done;
    14861389    int res = 0;        /*  FALSE */
    1487     int done;
    14881390    bool mntlistchg = FALSE;
    14891391    FILE *fin = NULL;
    14901392
    1491     malloc_string(command);
    14921393    malloc_string(boot_device);
    1493     malloc_string(tmp);
    1494     malloc_string(editor);
    1495     malloc_string(rootdev);
    1496     malloc_string(rootdrive);
    1497     malloc_string(conffile);
     1394
    14981395    assert_string_is_neither_NULL_nor_zerolength(bd);
    1499     strcpy(editor, find_my_editor());
    15001396    strcpy(boot_device, bd);
    15011397
    1502     if (!run_program_and_log_output("which grub-MR", FALSE)) {
    1503         log_msg(1, "Yay! grub-MR found...");
    1504         sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);
    1505         log_msg(1, "command = %s", command);
    1506     } else {
    1507         sprintf(command, "chroot " MNT_RESTORING " grub-install %s",
    1508                 boot_device);
    1509         log_msg(1, "WARNING - grub-MR not found; using grub-install");
    1510     }
    15111398    if (offer_to_run_stabgrub
    1512         && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
     1399        && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) {
    15131400        /* interactive mode */
    1514     {
    15151401        mvaddstr_and_log_it(g_currentY,
    15161402                            0,
     
    15211407        }
    15221408        for (done = FALSE; !done;) {
    1523             popup_and_get_string("Boot device",
    1524                                  "Please confirm/enter the boot device. If in doubt, try /dev/hda",
    1525                                  boot_device, MAX_STR_LEN / 4);
     1409            popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda", boot_device, MAX_STR_LEN / 4);
    15261410            /*  Only try to adapt grub here first if the mountlist wasn't changed before */
    15271411            if (! mntlistchg) {
    1528                 sprintf(command, "stabgrub-me %s", boot_device);
     1412                mr_asprintf(command, "stabgrub-me %s", boot_device);
    15291413                res = run_program_and_log_output(command, 1);
    1530             }
    1531             if ((res) || (mntlistchg)){
     1414                mr_free(command);
     1415            }
     1416
     1417            if ((res) || (mntlistchg)) {
    15321418                if (res) {
    15331419                    popup_and_OK("GRUB installation failed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
     
    15381424                    newtSuspend();
    15391425                }
    1540                 sprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
     1426                mr_asprintf(editor, "%s", find_my_editor());
     1427                mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
    15411428                paranoid_system(tmp);
    1542                 sprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
     1429                mr_free(tmp);
     1430
     1431                mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
    15431432                paranoid_system(tmp);
     1433                mr_free(tmp);
     1434   
    15441435                if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) {
    1545                     sprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
     1436                    mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
    15461437                } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) {
    1547                     sprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
     1438                    mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
    15481439                } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) {
    1549                     sprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);
     1440                    mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);
    15501441                }
    15511442                paranoid_system(tmp);
     1443                mr_free(tmp);
     1444   
    15521445                if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) {
    1553                     sprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
     1446                    mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
    15541447                } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) {
    1555                     sprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);
    1556                                 }
     1448                    mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);
     1449                }
    15571450                paranoid_system(tmp);
     1451                mr_free(tmp);
     1452                mr_free(editor);
     1453
    15581454                if (!g_text_mode) {
    15591455                    newtResume();
    15601456                }
    1561                 sprintf(command, "stabgrub-me %s", boot_device);
     1457                mr_asprintf(command, "stabgrub-me %s", boot_device);
    15621458                res = run_program_and_log_output(command, 1);
     1459                mr_free(command);
     1460
    15631461                if (res) {
    1564                     popup_and_OK
    1565                         ("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
     1462                    popup_and_OK("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
    15661463                    newtSuspend();
    15671464                    paranoid_system("chroot " MNT_RESTORING);
     
    15761473            }
    15771474        }
    1578     } else
     1475    } else {
    15791476        /* nuke mode */
    1580     {
    1581         mvaddstr_and_log_it(g_currentY,
    1582                             0,
    1583                             "Running GRUB...                                                 ");
     1477        if (!run_program_and_log_output("which grub-MR", FALSE)) {
     1478            log_msg(1, "Yay! grub-MR found...");
     1479            mr_asprintf(command, "grub-MR %s "MINDI_CACHE"/mountlist.txt", boot_device);
     1480            log_msg(1, "command = %s", command);
     1481        } else {
     1482            mr_asprintf(command, "chroot " MNT_RESTORING " grub-install %s", boot_device);
     1483            log_msg(1, "WARNING - grub-MR not found; using grub-install");
     1484        }
     1485        mvaddstr_and_log_it(g_currentY, 0, "Running GRUB...                                                 ");
    15841486        log_it("%s",command);
    15851487        res = run_program_and_log_output(command, 1);
     1488        mr_free(command);
     1489
    15861490        if (res) {
    15871491            popup_and_OK
     
    16091513        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    16101514    }
    1611     paranoid_free(rootdev);
    1612     paranoid_free(rootdrive);
    1613     paranoid_free(conffile);
    1614     paranoid_free(command);
    16151515    paranoid_free(boot_device);
    1616     paranoid_free(tmp);
    1617     paranoid_free(editor);
    16181516
    16191517    return (res);
     
    16331531{
    16341532  /** malloc **/
    1635     char *command;
    1636     char *tmp;
    1637     char *editor;
     1533    char *command = NULL;
     1534    char *tmp = NULL;
     1535    char *editor = NULL;
    16381536
    16391537    int res;
    16401538    int done;
    16411539
    1642     malloc_string(command);
    1643     malloc_string(tmp);
    1644     malloc_string(editor);
    1645     strcpy(editor, find_my_editor());
    16461540    if (offer_to_run_stabelilo
    16471541        && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
     
    16521546                            0,
    16531547                            "Modifying fstab and elilo.conf...                             ");
    1654         sprintf(command, "stabelilo-me");
     1548        mr_asprintf(command, "stabelilo-me");
    16551549        res = run_program_and_log_output(command, 3);
     1550        mr_free(command);
     1551
    16561552        if (res) {
    16571553            popup_and_OK
     
    16611557                    newtSuspend();
    16621558                }
    1663                 sprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
     1559                mr_asprintf(editor, "%s", find_my_editor());
     1560
     1561                mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
    16641562                paranoid_system(tmp);
    1665                 sprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor);
     1563                mr_free(tmp);
     1564
     1565                mr_asprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor);
    16661566                paranoid_system(tmp);
     1567                mr_free(tmp);
     1568                mr_free(editor);
     1569
    16671570                if (!g_text_mode) {
    16681571                    newtResume();
     
    16821585        res = TRUE;
    16831586    }
    1684     paranoid_free(command);
    1685     paranoid_free(tmp);
    1686     paranoid_free(editor);
    16871587    return (res);
    16881588}
     
    17011601{
    17021602  /** malloc **/
    1703     char *command;
    1704     char *tmp;
    1705     char *editor;
     1603    char *command = NULL;
     1604    char *tmp = NULL;
     1605    char *editor = NULL;
    17061606
    17071607    int res;
    17081608    int done;
    17091609    bool run_lilo_M = FALSE;
    1710     malloc_string(command);
    1711     malloc_string(tmp);
    1712     malloc_string(editor);
    17131610
    17141611    if (!run_program_and_log_output
     
    17171614    }
    17181615
    1719     strcpy(editor, find_my_editor());
    17201616    if (offer_to_run_stablilo
    17211617        && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
     
    17261622                            0,
    17271623                            "Modifying fstab and lilo.conf, and running LILO...                             ");
    1728         sprintf(command, "stablilo-me");
     1624        mr_asprintf(command, "stablilo-me");
    17291625        res = run_program_and_log_output(command, 3);
     1626        mr_free(command);
     1627
    17301628        if (res) {
    17311629            popup_and_OK
     
    17351633                    newtSuspend();
    17361634                }
    1737                 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1635                mr_asprintf(editor, "%s", find_my_editor());
     1636
     1637                mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    17381638                paranoid_system(tmp);
    1739                 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
     1639                mr_free(tmp);
     1640
     1641                mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
    17401642                paranoid_system(tmp);
     1643                mr_free(tmp);
     1644                mr_free(editor);
     1645
    17411646                if (!g_text_mode) {
    17421647                    newtResume();
     
    17931698                                   " lilo -M /dev/sda", 3);
    17941699    }
    1795     paranoid_free(command);
    1796     paranoid_free(tmp);
    1797     paranoid_free(editor);
    17981700    return (res);
    17991701}
     
    18131715{
    18141716  /** malloc **/
    1815     char *command;
    1816     char *boot_device;
    1817     char *tmp;
     1717    char *command = NULL;
     1718    char *boot_device = NULL;
     1719    char *tmp = NULL;
    18181720    char *editor;
    18191721    int res;
    18201722    int done;
    18211723
    1822     malloc_string(command);
    18231724    malloc_string(boot_device);
    1824     malloc_string(tmp);
    1825     malloc_string(editor);
    18261725    assert_string_is_neither_NULL_nor_zerolength(bd);
    18271726
    1828     strcpy(editor, find_my_editor());
    18291727    strcpy(boot_device, bd);
    1830     sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);
    1831     log_msg(2, "run_raw_mbr() --- command='%s'", command);
    18321728
    18331729    if (offer_to_hack_scripts
    1834         && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
     1730        && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) {
    18351731        /* interactive mode */
    1836     {
    18371732        mvaddstr_and_log_it(g_currentY, 0,
    18381733                            "Modifying fstab and restoring MBR...                           ");
     
    18431738                    newtSuspend();
    18441739                }
    1845                 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1740                mr_asprintf(editor, "%s", find_my_editor());
     1741                mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1742                mr_free(editor);
     1743
    18461744                paranoid_system(tmp);
     1745                mr_free(tmp);
    18471746                if (!g_text_mode) {
    18481747                    newtResume();
    18491748                }
    1850 //              newtCls();
    1851             }
    1852             popup_and_get_string("Boot device",
    1853                                  "Please confirm/enter the boot device. If in doubt, try /dev/hda",
    1854                                  boot_device, MAX_STR_LEN / 4);
    1855             sprintf(command, "stabraw-me %s", boot_device);
     1749            }
     1750            popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda", boot_device, MAX_STR_LEN / 4);
     1751            mr_asprintf(command, "stabraw-me %s", boot_device);
    18561752            res = run_program_and_log_output(command, 3);
     1753            mr_free(command);
     1754
    18571755            if (res) {
    18581756                done = ask_me_yes_or_no("Modifications failed. Re-try?");
     
    18611759            }
    18621760        }
    1863     } else
     1761    } else {
    18641762        /* nuke mode */
    1865     {
     1763        mr_asprintf(command, "raw-MR %s "MINDI_CACHE"/mountlist.txt", boot_device);
     1764        log_msg(2, "run_raw_mbr() --- command='%s'", command);
     1765
    18661766        mvaddstr_and_log_it(g_currentY, 0,
    18671767                            "Restoring MBR...                                               ");
    18681768        res = run_program_and_log_output(command, 3);
     1769        mr_free(command);
    18691770    }
    18701771    if (res) {
     
    18751776        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    18761777    }
    1877     paranoid_free(command);
    18781778    paranoid_free(boot_device);
    1879     paranoid_free(tmp);
    1880     paranoid_free(editor);
    18811779    return (res);
    18821780}
     
    19071805    malloc_string(g_mountlist_fname);
    19081806    malloc_string(g_mondo_home);
    1909     /*
    1910     malloc_string(g_tmpfs_mountpt);
    1911     */
    19121807    malloc_string(g_isodir_device);
    19131808    malloc_string(g_isodir_format);
     
    19461841    FILE *fin;
    19471842    FILE *fout;
    1948   /** malloc **/
    1949     char *incoming;
    1950     char *q;
     1843    char *incoming = NULL;
    19511844
    19521845    assert_string_is_neither_NULL_nor_zerolength(output_file);
    19531846    assert_string_is_neither_NULL_nor_zerolength(input_file);
    1954     malloc_string(incoming);
    19551847
    19561848    if (!(fin = fopen(input_file, "r"))) {
     
    19611853        fatal_error("cannot open output_file");
    19621854    }
    1963     for (q = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (q != NULL);
    1964          q = fgets(incoming, MAX_STR_LEN - 1, fin)) {
     1855    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
    19651856        if (strncmp(incoming, "etc/adjtime", 11)
    19661857            && strncmp(incoming, "etc/mtab", 8)
     
    19711862            && strncmp(incoming, "var/", 4))
    19721863            fprintf(fout, "%s", incoming);  /* don't need \n here, for some reason.. */
    1973     }
     1864        mr_free(incoming);
     1865    }
     1866    mr_free(incoming);
    19741867    paranoid_fclose(fout);
    19751868    paranoid_fclose(fin);
    1976     paranoid_free(incoming);
    19771869}
    19781870
     
    19891881    int i;
    19901882    /* MALLOC * */
    1991     char *tmp;
    1992 
    1993     malloc_string(tmp);
     1883    char *tmp = NULL;
     1884
    19941885    if (does_file_exist("/tmp/NOPAUSE")) {
    19951886        return;
     
    20011892    for (i = 0; i < 20; i++) {
    20021893        g_current_progress = i;
    2003         sprintf(tmp, "You have %d seconds left to abort.", 20 - i);
     1894        mr_asprintf(tmp, "You have %d seconds left to abort.", 20 - i);
    20041895        update_progress_form(tmp);
     1896        mr_free(tmp);
    20051897        sleep(1);
    20061898    }
    20071899    close_progress_form();
    2008     paranoid_free(tmp);
    20091900}
    20101901
     
    20241915    struct mountlist_itself *mountlist;
    20251916    int retval = 0, lino, res = 0, i;
    2026     char *command;
     1917    char *command = NULL;
    20271918    char *tmp = NULL;
    20281919
    2029     malloc_string(command);
    20301920    assert(p_external_copy_of_mountlist != NULL);
    20311921
     
    20351925    sort_mountlist_by_mountpoint(mountlist, 0);
    20361926
    2037     run_program_and_log_output("df -m", 3);
     1927    run_program_and_log_output("df -m -P", 3);
    20381928    mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices      ");
    20391929    open_progress_form("Unmounting devices",
     
    20541944    }
    20551945
    2056     paranoid_system("sync");
     1946    sync();
    20571947
    20581948    mr_asprintf(tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);
     
    20681958
    20691959    /* Unmounting the local /proc and /sys first */
    2070     run_program_and_log_output("umount " MNT_RESTORING "/proc",3);
    2071     run_program_and_log_output("umount " MNT_RESTORING "/sys",3);
     1960    run_program_and_log_output("umount -d " MNT_RESTORING "/proc",3);
     1961    run_program_and_log_output("umount -d " MNT_RESTORING "/sys",3);
    20721962
    20731963    for (lino = mountlist->entries - 1; lino >= 0; lino--) {
     
    20761966        }
    20771967        mr_asprintf(tmp, "Unmounting device %s  ", mountlist->el[lino].device);
    2078 
    20791968        update_progress_form(tmp);
    20801969
    20811970        if (is_this_device_mounted(mountlist->el[lino].device)) {
    20821971            if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
    2083                 sprintf(command, "swapoff %s", mountlist->el[lino].device);
     1972                mr_asprintf(command, "swapoff %s", mountlist->el[lino].device);
    20841973            } else {
    20851974                if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
    2086                     sprintf(command, "umount %s/", MNT_RESTORING);
     1975                    mr_asprintf(command, "umount -d %s/", MNT_RESTORING);
    20871976                    log_msg(3,
    20881977                            "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
    20891978                } else {
    2090                     sprintf(command, "umount " MNT_RESTORING "%s",
    2091                             mountlist->el[lino].mountpoint);
     1979                    mr_asprintf(command, "umount -d " MNT_RESTORING "%s", mountlist->el[lino].mountpoint);
    20921980
    20931981                    /* To support latest Ubuntu where /var is a separate FS
     
    21021990            log_msg(10, "The 'umount' command is '%s'", command);
    21031991            res = run_program_and_log_output(command, 3);
     1992            mr_free(command);
    21041993        } else {
    21051994            mr_strcat(tmp, "...not mounted anyway :-) OK");
     
    21282017    }
    21292018    free(mountlist);
    2130     paranoid_free(command);
    21312019    return (retval);
    21322020}
     
    21352023 *END_UNMOUNT_ALL_DEVICES                                                 *
    21362024 **************************************************************************/
    2137 
    2138 
    21392025
    21402026/**
     
    21462032int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
    21472033{
    2148     char *command;
     2034    char *command = NULL;
    21492035    int res = 0;
    2150 
    2151     malloc_string(command);
    21522036
    21532037    if (bkpinfo->use_obdr) {
     
    21582042    }
    21592043
    2160     sprintf(command,
    2161             "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx ./%s ./%s ./%s ./%s ./%s",
    2162             dev,
    2163             bkpinfo->internal_tape_block_size,
    2164             1024L * 1024 * 32 / bkpinfo->internal_tape_block_size,
    2165             MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
    2166             BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
     2044    mr_asprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx ./%s ./%s ./%s ./%s ./%s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
    21672045    log_msg(2, "command = '%s'", command);
    21682046    res = run_program_and_log_output(command, -1);
     2047    mr_free(command);
     2048
    21692049    if (res != 0) {
    21702050        if (does_file_exist(MONDO_CFG_FILE_STUB)) {
     
    21732053            /* Doing that allow us to remain compatible with pre-2.2.5 versions */
    21742054            log_msg(2, "pre-2.2.4 compatible mode on");
    2175             sprintf(command,
    2176                     "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s",
    2177                     dev,
    2178                     bkpinfo->internal_tape_block_size,
    2179                     1024L * 1024 * 32 / bkpinfo->internal_tape_block_size,
    2180                     MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
    2181                     BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
     2055            mr_sprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
    21822056            log_msg(2, "command = '%s'", command);
    21832057            res = run_program_and_log_output(command, -1);
     2058            mr_free(command);
    21842059            if ((res != 0) && (does_file_exist(MONDO_CFG_FILE_STUB))) {
    21852060                res = 0;
     
    21902065    return (res);
    21912066}
    2192 
    21932067
    21942068
     
    22062080
    22072081   /** malloc *****/
    2208     char *device;
    2209     char *command;
    2210     char *cfg_file;
    2211     char *mounted_cfgf_path;
    2212     char *tmp;
    2213     char *mountpt;
    2214     char *ramdisk_fname;
    2215     char *mountlist_file;
     2082    char *command = NULL;
     2083    char *cfg_file = NULL;
     2084    char *tmp = NULL;
     2085    char *mountpt = NULL;
     2086    char *mountlist_file = NULL;
    22162087    bool extract_mountlist_stub = FALSE;
    22172088    bool extract_i_want_my_lvm = FALSE;
     
    22202091
    22212092    assert(bkpinfo != NULL);
    2222     malloc_string(cfg_file);
    2223     malloc_string(mounted_cfgf_path);
    2224     malloc_string(mountpt);
    2225     malloc_string(ramdisk_fname);
    2226     malloc_string(mountlist_file);
    2227     malloc_string(device);
    2228     malloc_string(command);
    2229     malloc_string(tmp);
    22302093    log_msg(2, "gcffa --- starting");
    22312094    log_to_screen("I'm thinking...");
    2232     sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
    2233     device[0] = '\0';
     2095    mr_asprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
    22342096    if (chdir(bkpinfo->tmpdir)) {
    22352097        // FIXME
    22362098    }
    2237     strcpy(cfg_file, MONDO_CFG_FILE_STUB);
     2099    mr_asprintf(cfg_file, "%s", MONDO_CFG_FILE_STUB);
    22382100    unlink(cfg_file);           // cfg_file[] is missing the '/' at the start, FYI, by intent
     2101    mr_free(cfg_file);
     2102
    22392103    unlink(FILELIST_FULL_STUB);
    22402104    unlink(BIGGIELIST_TXT_STUB);
    2241     sprintf(command, "mkdir -p %s", mountpt);
     2105    mr _asprintf(command, "mkdir -p %s", mountpt);
    22422106    run_program_and_log_output(command, FALSE);
    2243 
    2244     sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
    2245     sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
    2246     //   make_hole_for_file( cfg_file );
    2247     //   make_hole_for_file( mountlist_file);
     2107    mr_free(command);
     2108
     2109    mr_asprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
     2110    mr_asprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
    22482111    log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
     2112    mr_free(mountpt);
    22492113
    22502114    if (!does_file_exist(cfg_file)) {
     
    22762140                log_msg(2, "media_device is blank; assuming %s");
    22772141            }
    2278             strcpy(tmp, bkpinfo->media_device);
     2142            mr_asprintf(tmp, "%s", bkpinfo->media_device);
    22792143            if (extract_cfg_file_and_mountlist_from_tape_dev
    22802144                (bkpinfo->media_device)) {
     
    22952159                }
    22962160            }
     2161            mr_free(tmp);
    22972162
    22982163            if (!does_file_exist("tmp/mondo-restore.cfg")) {
     
    23142179                log_msg(2,
    23152180                        "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz");
    2316                 sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);    // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
     2181                mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);    // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
    23172182                run_program_and_log_output(command, TRUE);
     2183                mr_free(command);
     2184
    23182185                if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
    23192186                    /* Doing that allow us to remain compatible with pre-2.2.5 versions */
    23202187                    log_msg(2, "pre-2.2.4 compatible mode on");
    2321                     sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);  // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
     2188                    mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);  // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
    23222189                    run_program_and_log_output(command, TRUE);
     2190                    mr_free(command);
    23232191                    if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
    23242192                        fatal_error
     
    23302198    if (does_file_exist(MONDO_CFG_FILE_STUB)) {
    23312199        log_msg(1, "gcffa --- great! We've got the config file");
    2332         sprintf(tmp, "%s/%s",
    2333                 call_program_and_get_last_line_of_output("pwd"),
    2334                 MONDO_CFG_FILE_STUB);
    2335         sprintf(command, "cp -f %s %s", tmp, cfg_file);
     2200        mr_asprintf(tmp, "%s/%s", call_program_and_get_last_line_of_output("pwd"), MONDO_CFG_FILE_STUB);
     2201        mr_asprintf(command, "cp -f %s %s", tmp, cfg_file);
    23362202        log_it("%s",command);
    23372203        if (strcmp(tmp, cfg_file)
     
    23432209            log_msg(1, "... and I moved it successfully to %s", cfg_file);
    23442210        }
    2345         sprintf(command, "cp -f %s/%s %s",
    2346             call_program_and_get_last_line_of_output("pwd"),
    2347             MOUNTLIST_FNAME_STUB, mountlist_file);
     2211        mr_free(command);
     2212
     2213        mr_asprintf(command, "cp -f %s/%s %s", call_program_and_get_last_line_of_output("pwd"), MOUNTLIST_FNAME_STUB, mountlist_file);
    23482214        log_it("%s",command);
    23492215        if (extract_mountlist_stub) {
     
    23532219            } else {
    23542220                log_msg(1, "Got mountlist too");
    2355                 sprintf(command, "cp -f %s %s", mountlist_file,
    2356                         g_mountlist_fname);
     2221                mr_free(command);
     2222                mr_asprintf(command, "cp -f %s %s", mountlist_file, g_mountlist_fname);
    23572223                if (run_program_and_log_output(command, 1)) {
    23582224                    log_msg(1, "Failed to copy mountlist to /tmp");
    23592225                } else {
    23602226                    log_msg(1, "Copied mountlist to /tmp as well OK");
    2361                     sprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
     2227                    mr_free(command);
     2228                    mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
    23622229                    run_program_and_log_output(command, 1);
    23632230                }
    23642231            }
    23652232        }
    2366     }
     2233        mr_free(command);
     2234        mr_free(tmp);
     2235    }
     2236
    23672237    run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
    23682238    if (!does_file_exist(cfg_file)) {
     
    23812251            /* Is this code really useful ??? */
    23822252        if (extract_mountlist_stub) {
    2383             sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
    2384                     bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
     2253            mr_asprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
    23852254            run_program_and_log_output(command, FALSE);
    2386         }
    2387     }
    2388 
    2389     sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
     2255            mr_free(command);
     2256        }
     2257    }
     2258
     2259    mr_asprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
     2260    mr_free(cfg_file);
     2261
    23902262    run_program_and_log_output(command, FALSE);
     2263    mr_free(command);
     2264
    23912265    if (extract_mountlist_stub) {
    2392         sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
     2266        mr_asprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
    23932267        run_program_and_log_output(command, FALSE);
    2394     }
    2395     sprintf(command, "cp -f etc/raidtab /etc/");
     2268        mr_free(command);
     2269    }
     2270    mr_free(mountlist_file);
     2271
     2272    mr_asprintf(command, "cp -f etc/raidtab /etc/");
    23962273    run_program_and_log_output(command, FALSE);
     2274    mr_free(command);
     2275
    23972276    if (extract_i_want_my_lvm) {
    2398         sprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
     2277        mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
    23992278        run_program_and_log_output(command, FALSE);
     2279        mr_free(command);
    24002280    }
    24012281    g_backup_media_type = bkpinfo->backup_media_type;
    2402     paranoid_free(device);
    2403     paranoid_free(command);
    2404     paranoid_free(tmp);
    2405     paranoid_free(cfg_file);
    2406     paranoid_free(mounted_cfgf_path);
    2407     paranoid_free(mountpt);
    2408     paranoid_free(ramdisk_fname);
    2409     paranoid_free(mountlist_file);
    24102282    return (retval);
    24112283}
     
    24162288
    24172289/* @} - end restoreUtilityGroup */
    2418 
    2419 
    2420 /***************************************************************************
    2421  * F@                                                                      *
    2422  * () -- Hugo Rabson                                  *
    2423  *                                                                         *
    2424  * Purpose:                                                                *
    2425  *                                                                         *
    2426  * Called by:                                                              *
    2427  * Params:    -                      -                                     *
    2428  * Returns:   0=success; nonzero=failure                                   *
    2429  ***************************************************************************/
    2430 
    2431 
    24322290
    24332291void wait_until_software_raids_are_prepped(char *mdstat_file, int wait_for_percentage)
     
    24362294    int unfinished_mdstat_devices = 9999;
    24372295    int i = 0;
    2438     char *screen_message;
    2439 
    2440     malloc_string(screen_message);
     2296    char *screen_message = NULL;
     2297
    24412298    raidlist = malloc(sizeof(struct raidlist_itself));
    24422299
     
    24582315                }
    24592316                log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i);
    2460                 sprintf(screen_message, "Sync'ing %s",
    2461                         raidlist->el[i].raid_device);
     2317                mr_asprintf(screen_message, "Sync'ing %s", raidlist->el[i].raid_device);
    24622318                open_evalcall_form(screen_message);
     2319                mr_free(screen_message);
     2320
    24632321                while (raidlist->el[i].progress < wait_for_percentage) {
    24642322                    log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress);
     
    24742332        }
    24752333    }
    2476     paranoid_free(screen_message);
    24772334    paranoid_free(raidlist);
    24782335}
    2479 
    2480 
  • branches/3.2/mondo/src/mondorestore/mondorestore.c

    r3185 r3193  
    253253              struct raidlist_itself *raidlist)
    254254{
    255     char c, *tmp;
     255    char c;
     256    char *tmp = NULL;
    256257    int retval = 0;
    257258
     
    260261    assert(mountlist != NULL);
    261262    assert(raidlist != NULL);
    262     malloc_string(tmp);
    263263    log_it("pre wrm");
    264264    c = which_restore_mode();
     
    274274        }
    275275        if (g_ISO_restore_mode) {
    276             sprintf(tmp, "umount -d %s", bkpinfo->isodir);
     276            mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir);
    277277            run_program_and_log_output(tmp, FALSE);
     278            mr_free(tmp);
    278279        }
    279280        paranoid_MR_finish(0);
     
    284285    if (bkpinfo->backup_media_type == iso) {
    285286        if (iso_fiddly_bits((c == 'N') ? TRUE : FALSE)) {
    286             log_msg(2, "catchall_mode --- iso_fiddly_bits returned w/ error");
     287            log_msg(2,
     288                    "catchall_mode --- iso_fiddly_bits returned w/ error");
    287289            return (1);
    288290        } else {
     
    301303        retval += compare_mode(mountlist, raidlist);
    302304    }
    303     paranoid_free(tmp);
    304305    return (retval);
    305306}
     
    418419 * @return 0 for success, or the number of errors encountered.
    419420 */
    420 int
    421 interactive_mode(struct mountlist_itself *mountlist,
    422                  struct raidlist_itself *raidlist)
     421int interactive_mode(struct mountlist_itself *mountlist, struct raidlist_itself *raidlist)
    423422{
    424423    int retval = 0;
     
    432431  /** needs malloc **********/
    433432    char *tmp;
    434     char *fstab_fname;
    435     char *old_restpath;
     433    char *p = NULL;
     434    char *tmp1 = NULL;
     435    char *fstab_fname = NULL;
     436    char *old_restpath = NULL;
    436437
    437438    struct s_node *filelist;
     
    442443
    443444    malloc_string(tmp);
    444     malloc_string(fstab_fname);
    445     malloc_string(old_restpath);
    446445    assert(bkpinfo != NULL);
    447446    assert(mountlist != NULL);
     
    451450
    452451    if (g_text_mode) {
    453         if (!ask_me_yes_or_no
    454             ("Interactive Mode + textonly = experimental! Proceed anyway?"))
    455         {
     452        if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?")) {
    456453            fatal_error("Wise move.");
    457454        }
     
    463460    log_it("Done loading config file; resizing ML");
    464461
    465 #ifdef __FreeBSD__
    466     if (strstr
    467         (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
    468          "noresize"))
    469 #else
    470     if (strstr
    471         (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
    472          "noresize"))
    473 #endif
    474     {
     462    mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat " CMDLINE);
     463    if (strstr(tmp1, "noresize")) {
    475464        log_msg(1, "Not resizing mountlist.");
    476465    } else {
    477466        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
    478467    }
     468    mr_free(tmp1);
     469
    479470    for (done = FALSE; !done;) {
    480471        log_it("About to edit mountlist");
    481472        if (g_text_mode) {
    482473            save_mountlist_to_disk(mountlist, g_mountlist_fname);
    483             sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
    484             res = system(tmp);
     474            mr_asprintf(tmp1, "%s %s", find_my_editor(), g_mountlist_fname);
     475            res = system(tmp1);
     476            mr_free(tmp1);
    485477            load_mountlist(mountlist, g_mountlist_fname);
    486478        } else {
     
    571563    }
    572564    /* restore */
    573     if ((restore_all =
    574          ask_me_yes_or_no("Do you want me to restore all of your data?")))
    575     {
     565    if ((restore_all = ask_me_yes_or_no("Do you want me to restore all of your data?"))) {
    576566        log_msg(1, "Restoring all data");
    577567        retval += restore_everything(NULL);
    578     } else
    579         if ((restore_all =
    580              ask_me_yes_or_no
    581              ("Do you want me to restore _some_ of your data?"))) {
    582         strcpy(old_restpath, bkpinfo->restore_path);
     568    } else if ((restore_all = ask_me_yes_or_no("Do you want me to restore _some_ of your data?"))) {
     569        mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
    583570        for (done = FALSE; !done;) {
    584571            unlink("/tmp/filelist.full");
     
    590577              gotos_suck:
    591578                strcpy(tmp, old_restpath);
    592 // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
     579                // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
    593580                if (popup_and_get_string
    594581                    ("Restore path", "Restore files to where?", tmp,
     
    608595                    free_filelist(filelist);
    609596                }
    610                 if (!ask_me_yes_or_no
    611                     ("Restore another subset of your backup?")) {
     597                if (!ask_me_yes_or_no("Restore another subset of your backup?")) {
    612598                    done = TRUE;
    613599                }
     
    616602            }
    617603        }
    618         strcpy(old_restpath, bkpinfo->restore_path);
    619     } else {
    620         mvaddstr_and_log_it(g_currentY++,
    621                             0,
    622                             "User opted not to restore any data.                                  ");
     604        mr_free(old_restpath);
     605    } else {
     606        mvaddstr_and_log_it(g_currentY++, 0, "User opted not to restore any data.                                  ");
    623607    }
    624608    if (retval) {
    625         mvaddstr_and_log_it(g_currentY++,
    626                             0,
    627                             "Errors occurred during the restore phase.            ");
     609        mvaddstr_and_log_it(g_currentY++, 0, "Errors occurred during the restore phase.            ");
    628610    }
    629611
     
    647629                            "Using tune2fs/tune4fs to identify your ext2,3,4 partitions");
    648630        if (does_file_exist("/tmp/fstab.new")) {
    649             strcpy(fstab_fname, "/tmp/fstab.new");
     631            mr_asprintf(fstab_fname, "/tmp/fstab.new");
    650632        } else {
    651             strcpy(fstab_fname, "/tmp/fstab");
    652         }
    653         sprintf(tmp,
    654                 "label-partitions-as-necessary %s < %s >> %s 2>> %s",
    655                 g_mountlist_fname, fstab_fname, MONDO_LOGFILE,
    656                 MONDO_LOGFILE);
    657         res = system(tmp);
     633            mr_asprintf(fstab_fname, "/tmp/fstab");
     634        }
     635        mr_asprintf(tmp1, "label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname, fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE);
     636        mr_free(fstab_fname);
     637
     638        res = system(tmp1);
     639        mr_free(tmp1);
    658640        if (res) {
    659641            log_to_screen
     
    674656  end_of_func:
    675657    paranoid_free(tmp);
    676     paranoid_free(fstab_fname);
    677     paranoid_free(old_restpath);
    678658    log_it("Leaving interactive_mode()");
    679659    return (retval);
     
    759739    int retval = 0;
    760740    int res = 0;
    761   /** malloc **/
    762     char tmp[MAX_STR_LEN];
     741    char *tmp = NULL;
     742    char *tmp1 = NULL;
    763743    char *flaws_str = NULL;
    764744
     
    772752    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo updated the mountlist
    773753#ifdef __FreeBSD__
    774     if (strstr
    775         (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
    776          "noresize"))
     754    if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize"))
    777755#else
    778     if (strstr
    779         (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
    780          "noresize"))
     756    if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize"))
    781757#endif
    782758    {
     
    812788            twenty_seconds_til_yikes();
    813789            g_fprep = fopen("/tmp/prep.sh", "w");
    814 #ifdef __FreeBSD__
    815             if (strstr
    816                 (call_program_and_get_last_line_of_output
    817                  ("cat /tmp/cmdline"), "nopart"))
    818 #else
    819             if (strstr
    820                 (call_program_and_get_last_line_of_output
    821                  ("cat /proc/cmdline"), "nopart"))
    822 #endif
    823             {
    824                 log_msg(2,
    825                         "Not partitioning drives due to 'nopart' option.");
     790            mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE));
     791            if (strstr(tmp1, "nopart")) {
     792                log_msg(2, "Not partitioning drives due to 'nopart' option.");
    826793                res = 0;
    827794            } else {
    828795                res = partition_everything(mountlist);
    829796                if (res) {
    830                     log_to_screen
    831                         ("Warning. Errors occurred during partitioning.");
     797                    log_to_screen("Warning. Errors occurred during partitioning.");
    832798                    res = 0;
    833799                }
    834800            }
     801            mr_free(tmp1);
     802
    835803            retval += res;
    836804            if (!res) {
    837805                log_to_screen("Preparing to format your disk(s)");
    838806                sleep(1);
    839                 paranoid_system("sync");
     807                sync();
    840808                log_to_screen("Please wait. This may take a few minutes.");
    841809                res += format_everything(mountlist, FALSE, raidlist);
     
    880848                        "Using tune2fs/tune4fs to identify your ext2,3,4 partitions");
    881849
    882     sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", g_mountlist_fname, MONDO_LOGFILE, MONDO_LOGFILE);
     850    mr_asprintf(tmp1, "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", MINDI_CACHE"/mountlist.txt", MONDO_LOGFILE, MONDO_LOGFILE);
    883851    res = run_program_and_log_output(tmp, TRUE);
     852    mr_free(tmp1);
    884853    if (res) {
    885854        log_to_screen("label-partitions-as-necessary returned an error");
     
    891860
    892861  after_the_nuke:
     862    mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE));
    893863    if (retval) {
    894864        log_to_screen("Errors occurred during the nuke phase.");
    895     } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) {
    896         log_to_screen
    897             ("PC was restored successfully. Thank you for using Mondo Rescue.");
    898         log_to_screen
    899             ("Please visit our website at http://www.mondorescue.org for more information.");
    900     } else {
    901         strcpy(tmp,"Mondo has restored your system.\n\nPlease wait for the command prompt. Then remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information.");
    902             popup_and_OK(tmp);
    903         log_to_screen
    904           ("Mondo has restored your system. Please wait for the command prompt.");
    905         log_to_screen
    906             ("Then remove the backup media and reboot.");
    907         log_to_screen
    908             ("Please visit our website at http://www.mondorescue.org for more information.");
    909     }
     865    } else if (strstr(tmp1, "RESTORE")) {
     866        log_to_screen("PC was restored successfully. Thank you for using Mondo Rescue.");
     867        log_to_screen("Please visit our website at http://www.mondorescue.org for more information.");
     868    } else {
     869        mr_asprintf(tmp,"%s","Mondo has restored your system.\n\nPlease wait for the command prompt. Then remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information.");
     870        popup_and_OK(tmp);
     871        mr_free(tmp);
     872        log_to_screen("Mondo has restored your system. Please wait for the command prompt.");
     873        log_to_screen("Then remove the backup media and reboot.");
     874        log_to_screen("Please visit our website at http://www.mondorescue.org for more information.");
     875    }
     876    mr_free(tmp1);
     877
    910878    g_I_have_just_nuked = TRUE;
    911879    return (retval);
     
    928896    int retval = 0;
    929897
    930   /** malloc **/
    931     char *old_restpath;
     898    char *old_restpath = NULL;
    932899
    933900    struct mountlist_itself *mountlist = NULL;
    934 //  static
    935901    struct raidlist_itself *raidlist = NULL;
    936902    struct s_node *filelist = NULL;
     
    938904    log_msg(1, "restore_to_live_filesystem() - starting");
    939905    assert(bkpinfo != NULL);
    940     malloc_string(old_restpath);
    941906    mountlist = malloc(sizeof(struct mountlist_itself));
    942907    raidlist = malloc(sizeof(struct raidlist_itself));
     
    974939    if (!g_restoring_live_from_netfs && (filelist = process_filelist_and_biggielist())) {
    975940        save_filelist(filelist, "/tmp/selected-files.txt");
    976         strcpy(old_restpath, bkpinfo->restore_path);
     941        mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
    977942        if (popup_and_get_string("Restore path",
    978943                                 "Restore files to where? )",
     
    986951        }
    987952        strcpy(bkpinfo->restore_path, old_restpath);
     953        mr_free(old_restpath);
    988954    } else {
    989955        if (filelist != NULL) {
     
    1004970        eject_device(bkpinfo->media_device);
    1005971    }
    1006     paranoid_free(old_restpath);
    1007972    free(mountlist);
    1008973    free(raidlist);
     
    10431008
    10441009  /** malloc ***/
    1045     char *checksum, *outfile_fname, *tmp, *bzip2_command,
    1046         *ntfsprog_command, *suffix, *sz_devfile;
     1010    char *checksum = NULL;
     1011    char *outfile_fname = NULL;
     1012    char *tmp = NULL;
     1013    char *bzip2_command = NULL;
     1014    char *suffix = NULL;
     1015    char *sz_devfile = NULL;
    10471016    char *bigblk;
    10481017    char *mds = NULL;
     
    10511020    long sliceno;
    10521021    long siz;
    1053     char ntfsprog_fifo[MAX_STR_LEN];
     1022    char *ntfsprog_fifo = NULL;
    10541023    char *file_to_openout = NULL;
    10551024    struct s_filename_and_lstat_info biggiestruct;
     
    10591028    int res = 0;
    10601029    int old_loglevel;
    1061     char sz_msg[MAX_STR_LEN];
    10621030    struct s_node *node;
    10631031
     
    10651033    ubuf = &the_utime_buf;
    10661034    assert(bkpinfo != NULL);
    1067 
    1068     malloc_string(checksum);
    1069     malloc_string(outfile_fname);
    1070     malloc_string(tmp);
    1071     malloc_string(bzip2_command);
    1072     malloc_string(ntfsprog_command);
    1073     malloc_string(suffix);
    1074     malloc_string(sz_devfile);
    10751035
    10761036    pathname_of_last_file_restored[0] = '\0';
     
    10921052    paranoid_fclose(fin);
    10931053
    1094     strcpy(checksum, biggiestruct.checksum);
    1095 
     1054    mr_asprintf(checksum, "%s", biggiestruct.checksum);
    10961055    if (!checksum[0]) {
    1097         sprintf(tmp, "Warning - bigfile %ld does not have a checksum",
    1098                 bigfileno + 1);
    1099         log_msg(3, tmp);
    1100     }
     1056        log_msg(3, "Warning - bigfile %ld does not have a checksum", bigfileno + 1);
     1057    }
     1058    mr_free(checksum);
    11011059
    11021060    if (!strncmp(biggiestruct.filename, "/dev/", 5))    // Whether NTFS or not :)
    11031061    {
    1104         strcpy(outfile_fname, biggiestruct.filename);
    1105     } else {
    1106         sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
    1107                 biggiestruct.filename);
     1062        mr_asprintf(outfile_fname, "%s", biggiestruct.filename);
     1063    } else {
     1064        mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, biggiestruct.filename);
    11081065    }
    11091066
     
    11121069        node = find_string_at_node(filelist, biggiestruct.filename);
    11131070        if (!node) {
    1114             log_msg(0, "Skipping %s (name isn't in filelist)",
    1115                     biggiestruct.filename);
     1071            log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename);
    11161072            pathname_of_last_file_restored[0] = '\0';
    11171073            return (0);
    11181074        } else if (!(node->selected)) {
    1119             log_msg(1, "Skipping %s (name isn't in biggielist subset)",
    1120                     biggiestruct.filename);
     1075            log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename);
    11211076            pathname_of_last_file_restored[0] = '\0';
    11221077            return (0);
    11231078        }
    11241079    }
     1080
    11251081    /* otherwise, continue */
    1126 
    11271082    log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
    11281083    if (biggiestruct.use_ntfsprog) {
    11291084        if (strncmp(biggiestruct.filename, "/dev/", 5)) {
    1130             log_msg(1,
    1131                     "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
     1085            log_msg(1, "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
    11321086            log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
    11331087            biggiestruct.use_ntfsprog = FALSE;
     
    11361090
    11371091    if (biggiestruct.use_ntfsprog)  // if it's an NTFS device
    1138 //  if (!strncmp ( biggiestruct.filename, "/dev/", 5))
    11391092    {
    11401093        g_loglevel = 4;
    11411094        use_ntfsprog_hack = TRUE;
    1142         log_msg(2,
    1143                 "Calling ntfsclone in background because %s is an NTFS /dev entry",
    1144                 outfile_fname);
    1145         sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
    1146                 (int) (random() % 32768));
     1095        log_msg(2, "Calling ntfsclone in background because %s is an NTFS /dev entry", outfile_fname);
     1096        mr_asprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), (int) (random() % 32768));
    11471097        mkfifo(sz_devfile, 0x770);
    1148         strcpy(ntfsprog_fifo, sz_devfile);
     1098        mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
     1099        mr_free(sz_devfile);
    11491100        file_to_openout = ntfsprog_fifo;
    11501101        switch (pid = fork()) {
     
    11521103            fatal_error("Fork failure");
    11531104        case 0:
    1154             log_msg(3,
    1155                     "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
    1156                     biggiestruct.filename, ntfsprog_fifo);
    1157             res =
    1158                 feed_outfrom_ntfsprog(biggiestruct.filename,
    1159                                        ntfsprog_fifo);
    1160 //          log_msg(3, "CHILD - fip - exiting");
     1105            log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", biggiestruct.filename, ntfsprog_fifo);
     1106            res = feed_outfrom_ntfsprog(biggiestruct.filename, ntfsprog_fifo);
     1107            mr_free(ntfsprog_fifo);
    11611108            exit(res);
    11621109            break;
    11631110        default:
    1164             log_msg(3,
    1165                     "feed_into_ntfsprog() called in background --- pid=%ld",
    1166                     (long int) (pid));
    1167         }
     1111            log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
     1112        }
     1113        mr_free(ntfsprog_fifo);
    11681114    } else {
    11691115        use_ntfsprog_hack = FALSE;
    1170         ntfsprog_fifo[0] = '\0';
    11711116        file_to_openout = outfile_fname;
    11721117        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    11761121    }
    11771122
    1178     sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1,
    1179             outfile_fname);
    1180     log_msg(2, tmp);
     1123    log_msg(2, "Reassembling big file %ld (%s)", bigfileno + 1, outfile_fname);
    11811124
    11821125    /*
     
    11861129     */
    11871130
    1188     strncpy(pathname_of_last_file_restored, biggiestruct.filename,
    1189             MAX_STR_LEN - 1);
     1131    strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN - 1);
    11901132    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
    11911133
     
    11981140
    11991141    for (sliceno = 1, finished = FALSE; !finished;) {
    1200         if (!does_file_exist
    1201             (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
    1202             &&
    1203             !does_file_exist(slice_fname
    1204                              (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
    1205             &&
    1206             !does_file_exist(slice_fname
    1207                              (bigfileno, sliceno, ARCHIVES_PATH, "gz"))
    1208             &&
    1209             !does_file_exist(slice_fname
    1210                              (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
    1211             log_msg(3,
    1212                     "Cannot find a data slice or terminator slice on CD %d",
    1213                     g_current_media_number);
     1142        if (!does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) &&
     1143            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo")) &&
     1144            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz")) &&
     1145            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzma")) &&
     1146            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1147            log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number);
    12141148            g_current_media_number++;
    12151149            mds = media_descriptor_string(bkpinfo->backup_media_type);
    1216             sprintf(tmp,
    1217                     "Asking for %s #%d so that I may read slice #%ld\n", mds,
    1218                     g_current_media_number, sliceno);
    1219             log_msg(2, tmp);
    1220             sprintf(tmp, "Restoring from %s #%d", mds, g_current_media_number);
     1150            log_msg(2, "Asking for %s #%d so that I may read slice #%ld\n", mds, g_current_media_number, sliceno);
    12211151            mr_free(mds);
    12221152
    1223             log_to_screen(tmp);
     1153            log_to_screen("Restoring from %s #%d", mds, g_current_media_number);
     1154
    12241155            insist_on_this_cd_number(g_current_media_number);
    12251156            log_to_screen("Continuing to restore.");
    12261157        } else {
    1227             strcpy(tmp,
    1228                    slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
     1158            mr_asprintf(tmp, "%s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
    12291159            if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
    1230                 log_msg(2,
    1231                         "End of bigfile # %ld (slice %ld is the terminator)",
    1232                         bigfileno + 1, sliceno);
     1160                log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno);
    12331161                finished = TRUE;
     1162                mr_free(tmp);
    12341163                continue;
    12351164            } else {
    1236                 if (does_file_exist
    1237                     (slice_fname
    1238                      (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
    1239                     strcpy(bzip2_command, "lzop");
    1240                     strcpy(suffix, "lzo");
     1165                if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
     1166                    mr_asprintf(bzip2_command, "lzop");
     1167                    mr_asprintf(suffix, "lzo");
    12411168                } else
    1242                     if (does_file_exist
    1243                         (slice_fname
    1244                          (bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
    1245                     strcpy(bzip2_command, "gzip");
    1246                     strcpy(suffix, "gz");
     1169                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
     1170                    mr_asprintf(bzip2_command, "gzip");
     1171                    mr_asprintf(suffix, "gz");
    12471172                } else
    1248                     if (does_file_exist
    1249                         (slice_fname
    1250                          (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
    1251                     strcpy(bzip2_command, "bzip2");
    1252                     strcpy(suffix, "bz2");
     1173                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzma"))) {
     1174                    mr_asprintf(bzip2_command, "lzma");
     1175                    mr_asprintf(suffix, "lzma");
    12531176                } else
    1254                     if (does_file_exist
    1255                         (slice_fname
    1256                          (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
    1257                     strcpy(bzip2_command, "");
    1258                     strcpy(suffix, "");
     1177                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1178                    mr_asprintf(bzip2_command, "bzip2");
     1179                    mr_asprintf(suffix, "bz2");
     1180                } else
     1181                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))) {
     1182                    mr_asprintf(bzip2_command, "");
     1183                    mr_asprintf(suffix, "");
    12591184                } else {
    12601185                    log_to_screen("OK, that's pretty fsck0red...");
     1186                    mr_free(tmp);
    12611187                    return (1);
    12621188                }
    12631189            }
    1264             if (bzip2_command[0] != '\0') {
    1265                 sprintf(bzip2_command + strlen(bzip2_command),
    1266                         " -dc %s 2>> %s",
    1267                         slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
    1268                                     suffix), MONDO_LOGFILE);
     1190            mr_free(tmp);
     1191            if (bzip2_command != NULL) {
     1192                mr_strcat(bzip2_command, " -dc %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
    12691193            } else {
    1270                 sprintf(bzip2_command, "cat %s 2>> %s",
    1271                         slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
    1272                                     suffix), MONDO_LOGFILE);
    1273             }
     1194                mr_asprintf(bzip2_command, "cat %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
     1195            }
     1196            mr_free(suffix);
     1197
    12741198            mds = media_descriptor_string(bkpinfo->backup_media_type);
    1275             sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ", mds,
    1276                     g_current_media_number, bigfileno + 1, sliceno);
     1199            mr_asprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ", mds, g_current_media_number, bigfileno + 1, sliceno);
    12771200            mr_free(mds);
    12781201            log_msg(2, tmp);
     
    12841207                update_progress_form(tmp);
    12851208            }
     1209            mr_free(tmp);
     1210
    12861211            if (!(fbzip2 = popen(bzip2_command, "r"))) {
    12871212                fatal_error("Can't run popen command");
    12881213            }
     1214            mr_free(bzip2_command);
     1215
    12891216            while (!feof(fbzip2)) {
    12901217                siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
    12911218                if (siz > 0) {
    1292                     sprintf(sz_msg, "Read %ld from fbzip2", siz);
    12931219                    siz = fwrite(bigblk, 1, siz, fout);
    1294                     sprintf(sz_msg + strlen(sz_msg),
    1295                             "; written %ld to fout", siz);
    1296 //        log_msg(2. sz_msg);
    12971220                }
    12981221            }
     
    13041227        }
    13051228    }
    1306 /*
    1307   memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy...
    1308   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1309   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1310   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1311   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1312 */
    13131229    paranoid_fclose(fout);
    13141230    g_loglevel = old_loglevel;
     
    13161232    if (use_ntfsprog_hack) {
    13171233        log_msg(3, "Waiting for ntfsclone to finish");
    1318         sprintf(tmp,
    1319                 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
     1234        mr_asprintf(tmp, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
    13201235        while (system(tmp) == 0) {
    13211236            sleep(1);
    13221237        }
     1238        mr_free(tmp);
    13231239        log_it("OK, ntfsclone has really finished");
    13241240    }
    13251241
    13261242    if (strcmp(outfile_fname, "/dev/null")) {
    1327         if (chown(outfile_fname, biggiestruct.properties.st_uid,
    1328               biggiestruct.properties.st_gid)) {
     1243        if (chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid)) {
    13291244            // FIXME
    13301245        }
     
    13341249        utime(outfile_fname, ubuf);
    13351250    }
     1251    mr_free(outfile_fname);
    13361252    paranoid_free(bigblk);
    1337     paranoid_free(checksum);
    1338     paranoid_free(outfile_fname);
    1339     paranoid_free(tmp);
    1340     paranoid_free(bzip2_command);
    1341     paranoid_free(ntfsprog_command);
    1342     paranoid_free(suffix);
    1343     paranoid_free(sz_devfile);
    13441253
    13451254    return (retval);
     
    13761285
    13771286  /** mallocs ********/
    1378     char *tmp;
    1379     char *command;
    1380     char *outfile_fname;
    1381     char *ntfsprog_command;
    1382     char *sz_devfile;
    1383     char *ntfsprog_fifo;
     1287    char *tmp = NULL;
     1288    char *tmp1 = NULL;
     1289    char *command = NULL;
     1290    char *outfile_fname = NULL;
     1291    char *sz_devfile = NULL;
     1292    char *ntfsprog_fifo = NULL;
    13841293    char *file_to_openout = NULL;
    13851294
     
    14001309
    14011310    malloc_string(tmp);
    1402     malloc_string(ntfsprog_fifo);
    1403     malloc_string(outfile_fname);
    1404     malloc_string(command);
    1405     malloc_string(sz_devfile);
    1406     malloc_string(ntfsprog_command);
    14071311    old_loglevel = g_loglevel;
    14081312    assert(bkpinfo != NULL);
     
    14551359    if (use_ntfsprog) {
    14561360        g_loglevel = 4;
    1457         strcpy(outfile_fname, orig_bf_fname);
     1361        mr_asprintf(outfile_fname, "%s", orig_bf_fname);
    14581362        use_ntfsprog_hack = TRUE;
    1459         log_msg(2,
    1460                 "Calling ntfsclone in background because %s is a /dev entry",
    1461                 outfile_fname);
    1462         sprintf(sz_devfile, "%s/%d.%d.000",
    1463                 bkpinfo->tmpdir,
    1464                 (int) (random() % 32768),
    1465                 (int) (random() % 32768));
     1363        log_msg(2, "Calling ntfsclone in background because %s is a /dev entry", outfile_fname);
     1364        mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768));
    14661365        mkfifo(sz_devfile, 0x770);
    1467         strcpy(ntfsprog_fifo, sz_devfile);
     1366        mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
     1367        mr_free(sz_devfile);
     1368
    14681369        file_to_openout = ntfsprog_fifo;
    14691370        switch (pid = fork()) {
     
    14711372            fatal_error("Fork failure");
    14721373        case 0:
    1473             log_msg(3,
    1474                     "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
    1475                     outfile_fname, ntfsprog_fifo);
    1476             res =
    1477                 feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
    1478 //          log_msg(3, "CHILD - fip - exiting");
     1374            log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", outfile_fname, ntfsprog_fifo);
     1375            res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
     1376            mr_free(ntfsprog_fifo);
    14791377            exit(res);
    14801378            break;
    14811379        default:
    1482             log_msg(3,
    1483                     "feed_into_ntfsprog() called in background --- pid=%ld",
    1484                     (long int) (pid));
    1485         }
    1486     } else {
    1487         if (!strncmp(orig_bf_fname, "/dev/", 5))    // non-NTFS partition
    1488         {
    1489             strcpy(outfile_fname, orig_bf_fname);
    1490         } else                  // biggiefile
    1491         {
    1492             sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
    1493                     orig_bf_fname);
     1380            log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
     1381        }
     1382        mr_free(ntfsprog_fifo);
     1383    } else {
     1384        if (!strncmp(orig_bf_fname, "/dev/", 5))    {
     1385            // non-NTFS partition
     1386            mr_asprintf(outfile_fname, "%s", orig_bf_fname);
     1387        } else {
     1388            // biggiefile
     1389            mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname);
    14941390        }
    14951391        use_ntfsprog_hack = FALSE;
    1496         ntfsprog_fifo[0] = '\0';
    14971392        file_to_openout = outfile_fname;
    14981393        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    15001395            make_hole_for_file(outfile_fname);
    15011396        }
    1502         sprintf(tmp, "Reassembling big file %ld (%s)",
    1503                 biggiefile_number + 1, orig_bf_fname);
    1504         log_msg(2, tmp);
     1397        log_msg(2, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname);
    15051398    }
    15061399
    15071400    if (dummy_restore) {
    1508         sprintf(outfile_fname, "/dev/null");
     1401        mr_free(outfile_fname);
     1402        mr_asprintf(outfile_fname, "/dev/null");
    15091403    }
    15101404
    15111405    if (!bkpinfo->zip_exe[0]) {
    1512         sprintf(command, "cat > \"%s\"", file_to_openout);
    1513     } else {
    1514         sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
    1515                 file_to_openout, MONDO_LOGFILE);
     1406        mr_asprintf(command, "cat > \"%s\"", file_to_openout);
     1407    } else {
     1408        mr_asprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE);
    15161409        if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
    15171410            /* Ignore SIGPIPE for gzip as it causes errors on big files
    1518              * Cf: http://trac.mondorescue.org/ticket/244
    1519              */
     1411             * Cf: http://trac.mondorescue.org/ticket/244 */
    15201412            signal(SIGPIPE,SIG_IGN);
    15211413        }
    15221414    }
    1523     sprintf(tmp, "Pipe command = '%s'", command);
    1524     log_msg(3, tmp);
     1415    log_msg(3, "Pipe command = '%s'", command);
    15251416
    15261417    /* restore biggiefile, one slice at a time */
     
    15281419        fatal_error("Cannot pipe out");
    15291420    }
     1421    mr_free(command);
     1422
    15301423    for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
    15311424         ctrl_chr != BLK_STOP_A_BIGGIE;
     
    15341427            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
    15351428        }
    1536         sprintf(tmp, "Working on file #%ld, slice #%ld    ",
    1537                 biggiefile_number + 1, current_slice_number);
    1538         log_msg(2, tmp);
     1429        log_msg(2, "Working on file #%ld, slice #%ld    ", biggiefile_number + 1, current_slice_number);
    15391430        if (!g_text_mode) {
    15401431            newtDrawRootText(0, g_noof_rows - 2, tmp);
     
    15751466    if (bkpinfo->zip_exe[0]) {
    15761467        if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
    1577             /* Re-enable SIGPIPE for gzip
    1578              */
     1468            /* Re-enable SIGPIPE for gzip */
    15791469            signal(SIGPIPE, terminate_daemon);
    15801470        }
     
    15861476    if (use_ntfsprog_hack) {
    15871477        log_msg(3, "Waiting for ntfsclone to finish");
    1588         sprintf(tmp,
    1589                 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
    1590         while (system(tmp) == 0) {
     1478        mr_asprintf(tmp1, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
     1479        while (system(tmp1) == 0) {
    15911480            sleep(1);
    15921481        }
     1482        mr_free(tmp1);
    15931483        log_msg(3, "OK, ntfsclone has really finished");
    15941484    }
     
    15981488    if (strcmp(outfile_fname, "/dev/null")) {
    15991489        chmod(outfile_fname, biggiestruct.properties.st_mode);
    1600         if (chown(outfile_fname, biggiestruct.properties.st_uid,
    1601               biggiestruct.properties.st_gid)) {
     1490        if (chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid)) {
    16021491            // FIXME
    16031492        }
     
    16061495        utime(outfile_fname, ubuf);
    16071496    }
     1497    mr_free(outfile_fname);
    16081498
    16091499    paranoid_free(tmp);
    1610     paranoid_free(outfile_fname);
    1611     paranoid_free(command);
    1612     paranoid_free(ntfsprog_command);
    1613     paranoid_free(sz_devfile);
    1614     paranoid_free(ntfsprog_fifo);
    16151500    g_loglevel = old_loglevel;
    16161501    return (retval);
     
    16451530  /** malloc **/
    16461531    char *command = NULL;
    1647     char *tmp;
    1648     char *filelist_name;
    1649     char *filelist_subset_fname;
    1650     char *executable;
    1651     char *temp_log;
    1652     char screen_message[100];
     1532    char *tmp = NULL;
     1533    char *filelist_name = NULL;
     1534    char *filelist_subset_fname = NULL;
     1535    char *executable = NULL;
     1536    char *temp_log = NULL;
    16531537    long matches = 0;
    16541538    bool use_star;
    1655     char *xattr_fname;
    1656     char *acl_fname;
    1657 //  char files_to_restore_this_time_fname[MAX_STR_LEN];
     1539    char *xattr_fname = NULL;
     1540    char *acl_fname = NULL;
    16581541
    16591542    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    1660     malloc_string(tmp);
    1661     malloc_string(filelist_name);
    1662     malloc_string(filelist_subset_fname);
    1663     malloc_string(executable);
    1664     malloc_string(temp_log);
    1665     malloc_string(xattr_fname);
    1666     malloc_string(acl_fname);
    16671543
    16681544    log_msg(5, "Entering");
    1669     filelist_subset_fname[0] = '\0';
    16701545    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    1671 //  sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());
    16721546    mr_asprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
    16731547    run_program_and_log_output(command, 9);
    16741548    paranoid_free(command);
    16751549
    1676     sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768),
    1677             (int) (random() % 32768));
    1678 
    1679     sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld",
    1680             current_tarball_number);
     1550    mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", current_tarball_number);
    16811551    if (length_of_file(filelist_name) <= 2) {
    1682         log_msg(2, "There are _zero_ files in filelist '%s'",
    1683                 filelist_name);
    1684         log_msg(2,
    1685                 "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
    1686         log_msg(2,
    1687                 "but it's non-critical. It's cosmetic. Don't worry about it.");
     1552        log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name);
     1553        log_msg(2, "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
     1554        log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it.");
    16881555        retval = 0;
    1689         goto leave_sub;
    1690     }
    1691     if (count_lines_in_file(filelist_name) <= 0
    1692         || length_of_file(tarball_fname) <= 0) {
     1556        mr_free(filelist_name);
     1557        log_msg(5, "Leaving");
     1558        return(0);
     1559    }
     1560    if (count_lines_in_file(filelist_name) <= 0 || length_of_file(tarball_fname) <= 0) {
    16931561        log_msg(3, "length_of_file(%s) = %llu", tarball_fname, length_of_file(tarball_fname));
    16941562        log_msg(3, "count_lines_in_file(%s) = %llu", tarball_fname, count_lines_in_file(tarball_fname));
    1695         sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)",
    1696                 current_tarball_number);
    1697         log_to_screen(tmp);
    1698         retval = 1;
    1699         goto leave_sub;
     1563        log_to_screen("Unable to restore fileset #%ld (CD I/O error)", current_tarball_number);
     1564        mr_free(filelist_name);
     1565        log_msg(5, "Leaving");
     1566        return(1);
    17001567    }
    17011568
    17021569    if (filelist) {
    1703         sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
    1704                 current_tarball_number);
     1570        mr_asprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number);
    17051571        if ((matches =
    17061572             save_filelist_entries_in_common(filelist_name, filelist,
    17071573                                             filelist_subset_fname,
    1708                                              use_star))
    1709             <= 0) {
    1710             sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
    1711             log_msg(1, tmp);
     1574                                             use_star)) <= 0) {
     1575            log_msg(1, "Skipping fileset %ld", current_tarball_number);
    17121576        } else {
    1713             log_msg(3, "Saved fileset %ld's subset to %s",
    1714                     current_tarball_number, filelist_subset_fname);
    1715         }
    1716         sprintf(screen_message, "Tarball #%ld --- %ld matches",
    1717                 current_tarball_number, matches);
    1718         log_to_screen(screen_message);
    1719     } else {
    1720         filelist_subset_fname[0] = '\0';
    1721     }
     1577            log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname);
     1578        }
     1579        log_to_screen("Tarball #%ld --- %ld matches", current_tarball_number, matches);
     1580    }
     1581    mr_free(filelist_name);
    17221582
    17231583    if (filelist == NULL || matches > 0) {
    17241584        if (g_getfattr) {
    1725             sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
    1726                 MNT_CDROM "/archives", current_tarball_number);
     1585            mr_asprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
    17271586        }
    17281587        if (g_getfacl) {
    1729             sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
    1730                 current_tarball_number);
     1588            mr_asprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
    17311589        }
    17321590        if (strstr(tarball_fname, ".bz2")) {
    1733             strcpy(executable, "bzip2");
     1591            mr_asprintf(executable, "bzip2");
     1592        } else if (strstr(tarball_fname, ".lzma")) {
     1593            mr_asprintf(executable, "lzma");
    17341594        } else if (strstr(tarball_fname, ".gz")) {
    1735             strcpy(executable, "gzip");
     1595            mr_asprintf(executable, "gzip");
    17361596        } else if (strstr(tarball_fname, ".lzo")) {
    1737             strcpy(executable, "lzop");
    1738         } else {
    1739             executable[0] = '\0';
    1740         }
    1741         if (executable[0]) {
    1742             sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
    1743             if (run_program_and_log_output(tmp, FALSE)) {
    1744                 log_to_screen
    1745                     ("(compare_a_tarball) Compression program %s not found - oh no!", executable);
     1597            mr_asprintf(executable, "lzop");
     1598        }
     1599        if (executable) {
     1600            mr_asprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
     1601            res = run_program_and_log_output(tmp, FALSE);
     1602            mr_free(tmp);
     1603
     1604            if (res) {
     1605                log_to_screen("(compare_a_tarball) Compression program %s not found - oh no!", executable);
    17461606                paranoid_MR_finish(1);
    17471607            }
    1748             strcpy(tmp, executable);
    1749             sprintf(executable, "-P %s -Z", tmp);
     1608            tmp = executable;
     1609            mr_asprintf(executable, "-P %s -Z", tmp);
     1610            mr_free(tmp);
    17501611        }
    17511612#ifdef __FreeBSD__
     
    17551616#endif
    17561617
    1757 //      if (strstr(tarball_fname, ".star."))
    17581618        if (use_star) {
    17591619            mr_asprintf(command, "star -x -force-remove -sparse -U " STAR_ACL_SZ " file=%s", tarball_fname);
     
    17621622            }
    17631623        } else {
    1764             if (filelist_subset_fname[0] != '\0') {
    1765                 mr_asprintf(command, "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, filelist_subset_fname, tarball_fname);
     1624            if (! executable) {
     1625                log_msg(2, "Mo executable, this shouldn't happen !");
    17661626            } else {
    1767                 mr_asprintf(command, "afio -i -b %ld -c %ld -M 8m %s %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, tarball_fname);
    1768             }
    1769         }
     1627                if (filelist_subset_fname != NULL) {
     1628                    mr_asprintf(command, "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, filelist_subset_fname, tarball_fname);
     1629                } else {
     1630                    mr_asprintf(command, "afio -i -b %ld -c %ld -M 8m %s %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, tarball_fname);
     1631                }
     1632            }
     1633        }
     1634        mr_free(executable);
    17701635
    17711636#undef BUFSIZE
     1637        mr_asprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), (int) (random() % 32768));
     1638
    17721639        mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log);
    17731640        log_msg(1, "command = '%s'", command);
     
    18281695            log_msg(2, "Fileset #%d processed OK", current_tarball_number);
    18291696        }
     1697        unlink(temp_log);
     1698        mr_free(temp_log);
    18301699    }
    18311700    if (does_file_exist("/PAUSE")) {
     
    18341703    }
    18351704    unlink(filelist_subset_fname);
    1836     unlink(xattr_fname);
    1837     unlink(acl_fname);
    1838     unlink(temp_log);
    1839 
    1840   leave_sub:
    1841     paranoid_free(tmp);
    1842     paranoid_free(filelist_name);
    1843     paranoid_free(filelist_subset_fname);
    1844     paranoid_free(executable);
    1845     paranoid_free(temp_log);
    1846     paranoid_free(xattr_fname);
    1847     paranoid_free(acl_fname);
     1705    mr_free(filelist_subset_fname);
     1706    if (g_getfattr) {
     1707        unlink(xattr_fname);
     1708        mr_free(xattr_fname);
     1709    }
     1710    if (g_getfacl) {
     1711        unlink(acl_fname);
     1712        mr_free(acl_fname);
     1713    }
     1714
    18481715    log_msg(5, "Leaving");
    18491716    return (retval);
     
    18811748
    18821749  /** malloc add ***/
    1883     char *tmp;
    18841750    char *mds = NULL;
    1885     char *command;
    1886     char *afio_fname;
    1887     char *filelist_fname;
    1888     char *filelist_subset_fname;
    1889     char *executable;
     1751    char *command = NULL;
     1752    char *afio_fname = NULL;
     1753    char *filelist_fname = NULL;
     1754    char *filelist_subset_fname = NULL;
     1755    char *executable = NULL;
    18901756    long matches = 0;
    18911757    bool restore_this_fileset = FALSE;
     
    18941760    assert(bkpinfo != NULL);
    18951761    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    1896     malloc_string(filelist_subset_fname);
    1897     malloc_string(filelist_fname);
    1898     malloc_string(afio_fname);
    1899     malloc_string(executable);
    1900     malloc_string(command);
    1901     malloc_string(tmp);
    1902     filelist_subset_fname[0] = '\0';
     1762
    19031763    /* to do it with a file... */
    19041764    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    19051765    mds = media_descriptor_string(bkpinfo->backup_media_type);
    1906     sprintf(tmp,
    1907             "Restoring from fileset #%ld (%ld KB) on %s #%d",
     1766    log_msg(2, "Restoring from fileset #%ld (%ld KB) on %s #%d",
    19081767            current_tarball_number, (long) size >> 10, mds, g_current_media_number);
    19091768    mr_free(mds);
    19101769
    1911     log_msg(2, tmp);
    19121770    run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
    19131771
     
    19171775   * in afio or someting; oh darn.. OK, use tmpfs :-)                         *
    19181776   ****************************************************************************/
    1919     filelist_fname[0] = filelist_subset_fname[0] = '\0';
    1920     sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
    1921             current_tarball_number);
    1922     sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
    1923             current_tarball_number);
    1924     sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
    1925             bkpinfo->tmpdir, current_tarball_number);
    1926 //  sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
     1777    mr_asprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number);
     1778    mr_asprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number);
     1779    mr_asprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number);
     1780
    19271781    res = read_file_from_stream_to_file(afio_fname, size);
    19281782    if (strstr(tarball_fname, ".star")) {
     
    19331787    }
    19341788    if (bkpinfo->compression_level == 0) {
    1935         executable[0] = '\0';
     1789        mr_asprintf(executable, "%s", "");
    19361790    } else {
    19371791        if (bkpinfo->use_star) {
    1938             strcpy(executable, " -bz");
     1792            mr_asprintf(executable, "%s", " -bz");
    19391793        } else {
    1940             sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
     1794            mr_asprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
    19411795        }
    19421796    }
     
    19491803        if (strstr(tarball_fname, ".star.")) {
    19501804            use_star = TRUE;
    1951             sprintf(command, "star -sparse -t file=%s %s", afio_fname, executable);
     1805            mr_asprintf(command, "star -sparse -t file=%s %s", afio_fname, executable);
    19521806        } else {
    19531807            use_star = FALSE;
    1954             sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
    1955                     executable, afio_fname);
    1956         }
    1957         sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname,
    1958                 MONDO_LOGFILE);
     1808            mr_asprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, executable, afio_fname);
     1809        }
     1810        mr_strcat(command, " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
    19591811        log_msg(1, "command = %s", command);
    19601812        if (system(command)) {
    19611813            log_msg(4, "Warning - error occurred while retrieving TOC");
    19621814        }
     1815        mr_free(command);
     1816
    19631817        if ((matches =
    19641818             save_filelist_entries_in_common(filelist_fname, filelist,
     
    19701824                        current_tarball_number);
    19711825            }
    1972             sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
    1973             log_msg(2, tmp);
     1826            log_msg(2, "Skipping fileset %ld", current_tarball_number);
    19741827            restore_this_fileset = FALSE;
    19751828        } else {
     
    19821835
    19831836// Concoct the call to star/afio to restore files
    1984     if (strstr(tarball_fname, ".star."))    // star
    1985     {
    1986         sprintf(command, "star -sparse -x file=%s %s", afio_fname, executable);
     1837    if (strstr(tarball_fname, ".star.")) {
     1838        // star
     1839        mr_asprintf(command, "star -sparse -x file=%s %s", afio_fname, executable);
    19871840        if (filelist) {
    1988             sprintf(command + strlen(command), " list=%s",
    1989                     filelist_subset_fname);
    1990         }
    1991     } else                      // afio
    1992     {
    1993         sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,
    1994                 executable);
     1841            mr_strcat(command, " list=%s", filelist_subset_fname);
     1842        }
     1843    } else {
     1844        // afio
     1845        mr_asprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable);
    19951846        if (filelist) {
    1996             sprintf(command + strlen(command), " -w %s",
    1997                     filelist_subset_fname);
    1998         }
    1999         sprintf(command + strlen(command), " %s", afio_fname);
    2000     }
    2001     sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
     1847            mr_strcat(command, " -w %s", filelist_subset_fname);
     1848        }
     1849        mr_strcat(command, " %s", afio_fname);
     1850    }
     1851    mr_strcat(command, " 2>> %s", MONDO_LOGFILE);
     1852    mr_free(executable);
    20021853
    20031854// Call if IF there are files to restore (selectively/unconditionally)
     
    20311882        log_msg(1, "NOT CALLING '%s'", command);
    20321883    }
     1884    mr_free(command);
    20331885
    20341886    if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
     
    20381890
    20391891    unlink(filelist_subset_fname);
     1892    mr_free(filelist_subset_fname);
    20401893    unlink(filelist_fname);
     1894    mr_free(filelist_fname);
    20411895    unlink(afio_fname);
    2042 
    2043     paranoid_free(filelist_subset_fname);
    2044     paranoid_free(filelist_fname);
    2045     paranoid_free(afio_fname);
    2046     paranoid_free(command);
    2047     paranoid_free(tmp);
     1896    mr_free(afio_fname);
     1897
    20481898    return (retval);
    20491899}
     
    20651915 * @return 0 for success, nonzero for failure.
    20661916 */
    2067 int
    2068 restore_all_biggiefiles_from_CD(struct s_node *filelist)
    2069 {
     1917int restore_all_biggiefiles_from_CD(struct s_node *filelist) {
     1918
    20701919    int retval = 0;
    20711920    int res = 0;
    20721921    long noof_biggiefiles, bigfileno = 0, total_slices;
    20731922  /** malloc **/
    2074     char *tmp;
     1923    char *tmp = NULL;
     1924    char *tmp1 = NULL;
    20751925    char *mds = NULL;
    20761926    bool just_changed_cds = FALSE;
    2077     char *xattr_fname;
    2078     char *acl_fname;
    2079     char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
     1927    char *xattr_fname = NULL;
     1928    char *acl_fname = NULL;
     1929    char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
    20801930    char *pathname_of_last_biggie_restored;
    20811931    FILE *fbw = NULL;
    20821932
    2083     malloc_string(xattr_fname);
    2084     malloc_string(acl_fname);
     1933    malloc_string(pathname_of_last_biggie_restored);
    20851934    malloc_string(tmp);
    2086     malloc_string(biggies_whose_EXATs_we_should_set);
    2087     malloc_string(pathname_of_last_biggie_restored);
    20881935    assert(bkpinfo != NULL);
    20891936
    2090     sprintf(biggies_whose_EXATs_we_should_set,
    2091             "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
     1937    mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
    20921938    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
    2093         log_msg(1, "Warning - cannot openout %s",
    2094                 biggies_whose_EXATs_we_should_set);
     1939        log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
    20951940    }
    20961941
    20971942    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
    20981943    total_slices = atol(tmp);
    2099     sprintf(tmp, "Reassembling large files      ");
    2100     mvaddstr_and_log_it(g_currentY, 0, tmp);
     1944    mr_free(tmp);
     1945
     1946    mr_asprintf(tmp1, "Reassembling large files      ");
     1947    mvaddstr_and_log_it(g_currentY, 0, tmp1);
     1948    mr_free(tmp1);
     1949
    21011950    if (length_of_file(BIGGIELIST) < 6) {
    21021951        log_msg(1, "OK, no biggielist; not restoring biggiefiles");
     
    21051954    noof_biggiefiles = count_lines_in_file(BIGGIELIST);
    21061955    if (noof_biggiefiles <= 0) {
    2107         log_msg(2,
    2108                 "OK, no biggiefiles in biggielist; not restoring biggiefiles");
     1956        log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles");
    21091957        return (0);
    21101958    }
    2111     sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
    2112             noof_biggiefiles);
    2113     log_msg(2, tmp);
     1959    log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
    21141960
    21151961    open_progress_form("Reassembling large files",
     
    21201966        log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
    21211967        if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
    2122             log_msg(3,
    2123                     "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
     1968            log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
    21241969            mds = media_descriptor_string(bkpinfo->backup_media_type);
    2125             log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
    2126                     bigfileno + 1, mds,
    2127                     g_current_media_number);
     1970            log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno + 1, mds, g_current_media_number);
    21281971            log_msg(3, "Slicename would have been %s",
    21291972                    slice_fname(bigfileno, 0, ARCHIVES_PATH, ""));
     
    21311974            if (just_changed_cds) {
    21321975                just_changed_cds = FALSE;
    2133                 log_msg(3,
    2134                         "I'll continue to scan this CD for bigfiles to be restored.");
     1976                log_msg(3, "I'll continue to scan this CD for bigfiles to be restored.");
    21351977            } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
    21361978                insist_on_this_cd_number(++g_current_media_number);
    2137                 sprintf(tmp, "Restoring from %s #%d", mds,
    2138                         g_current_media_number);
    2139                 log_to_screen(tmp);
     1979                log_to_screen("Restoring from %s #%d", mds, g_current_media_number);
    21401980                just_changed_cds = TRUE;
    21411981            } else {
    21421982                /* That big file doesn't exist, but the followings may */
    21431983                /* So we need to continue looping */
    2144                 log_msg(2, "There was no bigfile #%ld. That's OK.",
    2145                     bigfileno + 1);
     1984                log_msg(2, "There was no bigfile #%ld. That's OK.", bigfileno + 1);
    21461985                log_msg(2, "I'm going to stop restoring bigfiles now.");
    21471986                retval++;
     
    21511990        } else {
    21521991            just_changed_cds = FALSE;
    2153             sprintf(tmp, "Restoring big file %ld", bigfileno + 1);
    2154             update_progress_form(tmp);
    2155             res =
    2156                 restore_a_biggiefile_from_CD(bigfileno, filelist, pathname_of_last_biggie_restored);
     1992            mr_asprintf(tmp1, "Restoring big file %ld", bigfileno + 1);
     1993            update_progress_form(tmp1);
     1994            mr_free(tmp1);
     1995            res = restore_a_biggiefile_from_CD(bigfileno, filelist, pathname_of_last_biggie_restored);
    21571996            log_it("%s",pathname_of_last_biggie_restored);
    21581997            if (fbw && pathname_of_last_biggie_restored[0]) {
     
    21682007        fclose(fbw);
    21692008        if (g_getfattr) {
    2170             sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
     2009            mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
    21712010            if (length_of_file(xattr_fname) > 0) {
    21722011                set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
    21732012            }
     2013            mr_free(xattr_fname);
    21742014        }
    21752015        if (g_getfacl) {
    2176             sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
     2016            mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
    21772017            if (length_of_file(acl_fname) > 0) {
    21782018                set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
    21792019            }
    2180         }
    2181     }
     2020            mr_free(acl_fname);
     2021        }
     2022    }
     2023    mr_free(biggies_whose_EXATs_we_should_set);
     2024
    21822025    if (does_file_exist("/PAUSE")) {
    2183         popup_and_OK
    2184             ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
     2026        popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
    21852027    }
    21862028    close_progress_form();
     
    21902032        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    21912033    }
    2192     paranoid_free(xattr_fname);
    2193     paranoid_free(acl_fname);
    2194     paranoid_free(tmp);
    2195     paranoid_free(biggies_whose_EXATs_we_should_set);
    21962034    paranoid_free(pathname_of_last_biggie_restored);
    21972035    return (retval);
     
    22202058    int res;
    22212059    int attempts;
    2222     long current_tarball_number = 0;
     2060    long current_tarball_number = 0L;
    22232061    long max_val;
    22242062  /**malloc ***/
     2063    char *mds = NULL;
    22252064    char *tmp = NULL;
    2226     char *mds = NULL;
    22272065    char *tmp1 = NULL;
    2228     char *tarball_fname;
    2229     char *progress_str;
    2230     char *comment;
     2066    char *tarball_fname = NULL;
     2067    char *progress_str = NULL;
     2068
     2069    assert(bkpinfo != NULL);
    22312070
    22322071    malloc_string(tmp);
    2233     malloc_string(tarball_fname);
    2234     malloc_string(progress_str);
    2235     malloc_string(comment);
    2236 
    2237     assert(bkpinfo != NULL);
    2238 
    22392072    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
    2240     log_msg(2,
    2241             "Insisting on 1st media, so that I can have a look at LAST-FILELIST-NUMBER");
     2073    log_msg(2, "Insisting on 1st media, so that I can have a look at LAST-FILELIST-NUMBER");
    22422074    if (g_current_media_number != 1) {
    22432075        log_msg(3, "OK, that's jacked up.");
     
    22502082
    22512083    mds = media_descriptor_string(bkpinfo->backup_media_type);
    2252     sprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number);
     2084    mr_asprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number);
    22532085
    22542086    log_to_screen(progress_str);
     
    22602092        insist_on_this_cd_number(g_current_media_number);
    22612093        update_progress_form(progress_str);
    2262         sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
    2263                 current_tarball_number);
     2094        mr_free(progress_str);
     2095
     2096        mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", current_tarball_number);
    22642097        if (!does_file_exist(tarball_fname)) {
    2265             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz",
    2266                 current_tarball_number);
     2098            mr_free(tarball_fname);
     2099            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz", current_tarball_number);
    22672100        }
    22682101        if (!does_file_exist(tarball_fname)) {
    2269             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
    2270                     current_tarball_number);
     2102            mr_free(tarball_fname);
     2103            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzma", current_tarball_number);
    22712104        }
    22722105        if (!does_file_exist(tarball_fname)) {
    2273             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
    2274                     current_tarball_number);
     2106            mr_free(tarball_fname);
     2107            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo", current_tarball_number);
    22752108        }
    22762109        if (!does_file_exist(tarball_fname)) {
    2277             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
    2278                     current_tarball_number);
     2110            mr_free(tarball_fname);
     2111            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.", current_tarball_number);
    22792112        }
    22802113        if (!does_file_exist(tarball_fname)) {
    2281             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
    2282                     current_tarball_number);
     2114            mr_free(tarball_fname);
     2115            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2", current_tarball_number);
     2116        }
     2117        if (!does_file_exist(tarball_fname)) {
     2118            mr_free(tarball_fname);
     2119            mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", current_tarball_number);
    22832120        }
    22842121        if (!does_file_exist(tarball_fname)) {
     
    22862123                log_to_screen
    22872124                    ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
     2125                mr_free(tarball_fname);
    22882126                return (0);
    22892127            }
     
    22952133            }
    22962134            g_current_media_number++;
    2297             sprintf(progress_str, "Restoring from %s #%d",
    2298                     media_descriptor_string(bkpinfo->backup_media_type),
    2299                     g_current_media_number);
     2135            mr_asprintf(progress_str, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    23002136            log_to_screen(progress_str);
    23012137        } else {
    2302             sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
    2303                     current_tarball_number, mds, g_current_media_number);
    2304 //    log_msg(3, "progress_str = %s", progress_str);
    2305             for (res = 999, attempts = 0; attempts < 3 && res != 0;
    2306                  attempts++) {
    2307                 res =
    2308                     restore_a_tarball_from_CD(tarball_fname,
    2309                                               current_tarball_number,
    2310                                               filelist);
    2311             }
    2312             mr_asprintf(tmp1, "%s #%d, fileset #%ld - restore ",
    2313                     mds, g_current_media_number, current_tarball_number);
     2138            mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_tarball_number, mds, g_current_media_number);
     2139            for (res = 999, attempts = 0; attempts < 3 && res != 0; attempts++) {
     2140                res = restore_a_tarball_from_CD(tarball_fname, current_tarball_number, filelist);
     2141            }
     2142            mr_asprintf(tmp1, "%s #%d, fileset #%ld - restore ", mds, g_current_media_number, current_tarball_number);
    23142143            if (res) {
    23152144                mr_strcat(tmp1, "reported errors");
     
    23222151                mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
    23232152            }
    2324             strcpy(comment, tmp1);
    2325             paranoid_free(tmp1);
    23262153            if (attempts > 1) {
    2327                 log_to_screen(comment);
    2328             }
     2154                log_to_screen(tmp1);
     2155            }
     2156            mr_free(tmp1);
    23292157
    23302158            retval += res;
     
    23322160            g_current_progress++;
    23332161        }
     2162        mr_free(tarball_fname);
     2163
    23342164        /* Now we need to umount the current media to have the next mounted by insist_on_this_cd_number */
    23352165        /*   run_program_and_log_output("umount " MNT_CDROM, FALSE); */
    23362166    }
    23372167    mr_free(mds);
     2168    mr_free(progress_str);
    23382169
    23392170    close_progress_form();
     
    23432174        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    23442175    }
    2345     paranoid_free(tarball_fname);
    2346     paranoid_free(progress_str);
    2347     paranoid_free(comment);
    23482176
    23492177    return (retval);
     
    23752203
    23762204  /** malloc add ****/
    2377     char *tmp;
     2205    char *tmp = NULL;
    23782206    char *biggie_fname;
    23792207    char *biggie_cksum;
    2380     char *xattr_fname;
    2381     char *acl_fname;
     2208    char *xattr_fname = NULL;
     2209    char *acl_fname = NULL;
    23822210    char *p;
    23832211    char *pathname_of_last_biggie_restored;
    2384     char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
     2212    char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
    23852213    long long biggie_size;
    23862214    FILE *fbw = NULL;
     
    23892217    malloc_string(biggie_fname);
    23902218    malloc_string(biggie_cksum);
    2391     malloc_string(xattr_fname);
    2392     malloc_string(acl_fname);
    2393     malloc_string(biggies_whose_EXATs_we_should_set);
    23942219    malloc_string(pathname_of_last_biggie_restored);
    23952220    assert(bkpinfo != NULL);
     
    23982223
    23992224    total_slices = atol(tmp);
    2400     sprintf(tmp, "Reassembling large files      ");
     2225
    24012226    if (g_getfattr) {
    2402         sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2227        mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    24032228    }
    24042229    if (g_getfacl) {
    2405         sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    2406     }
    2407     mvaddstr_and_log_it(g_currentY, 0, tmp);
    2408     sprintf(biggies_whose_EXATs_we_should_set,
    2409             "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
     2230        mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2231    }
     2232    mr_asprintf(tmp1, "Reassembling large files      ");
     2233    mvaddstr_and_log_it(g_currentY, 0, tmp1);
     2234    mr_free(tmp1);
     2235
     2236    mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
    24102237    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
    2411         log_msg(1, "Warning - cannot openout %s",
    2412                 biggies_whose_EXATs_we_should_set);
    2413     }
    2414 // get xattr and acl files if they're there
    2415     res =
    2416         read_header_block_from_stream(&biggie_size, biggie_fname,
    2417                                       &ctrl_chr);
     2238        log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
     2239    }
     2240
     2241    // get xattr and acl files if they're there
     2242    res = read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr);
    24182243    if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
    2419         res = read_EXAT_files_from_tape(&biggie_size, biggie_fname,
    2420                                       &ctrl_chr, xattr_fname, acl_fname);
     2244        res = read_EXAT_files_from_tape(&biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname);
    24212245    }
    24222246
    24232247    noof_biggiefiles = atol(biggie_fname);
    2424     sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
    2425             noof_biggiefiles);
    2426     log_msg(2, tmp);
     2248    log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
    24272249    open_progress_form("Reassembling large files",
    24282250                       "I am now reassembling all the large files.",
     
    24472269            p++;
    24482270        }
    2449         sprintf(tmp, "Restoring big file %ld (%lld K)",
    2450                 current_bigfile_number + 1, biggie_size / 1024);
    2451         update_progress_form(tmp);
     2271        mr_asprintf(tmp1, "Restoring big file %ld (%lld K)", current_bigfile_number + 1, biggie_size / 1024);
     2272        update_progress_form(tmp1);
     2273        mr_free(tmp1);
    24522274        res = restore_a_biggiefile_from_stream(biggie_fname,
    24532275                                               current_bigfile_number,
     
    24672289    if (current_bigfile_number != noof_biggiefiles
    24682290        && noof_biggiefiles != 0) {
    2469         sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
    2470                 current_bigfile_number, noof_biggiefiles);
    2471     } else {
    2472         sprintf(tmp,
    2473                 "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
    2474                 noof_biggiefiles, current_bigfile_number);
    2475     }
    2476     log_msg(1, tmp);
     2291        log_msg(1, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", current_bigfile_number, noof_biggiefiles);
     2292    } else {
     2293        log_msg(1, "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", noof_biggiefiles, current_bigfile_number);
     2294    }
    24772295
    24782296    if (fbw) {
     
    24822300            if (g_getfattr) {
    24832301                if (length_of_file(xattr_fname) > 0) {
    2484                     log_msg(1, "set_fattr_List(%s,%s)",
    2485                         biggies_whose_EXATs_we_should_set, xattr_fname);
    2486                     set_fattr_list(biggies_whose_EXATs_we_should_set,
    2487                                xattr_fname);
     2302                    log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname);
     2303                    set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
    24882304                }
    24892305            }
    24902306            if (g_getfacl) {
    24912307                if (length_of_file(acl_fname) > 0) {
    2492                     log_msg(1, "set_acl_list(%s,%s)",
    2493                             biggies_whose_EXATs_we_should_set, acl_fname);
     2308                    log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname);
    24942309                    set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
    24952310                }
     
    24992314        }
    25002315    }
     2316    mr_free(xattr_fname);
     2317    mr_free(acl_fname);
     2318    mr_free(biggies_whose_EXATs_we_should_set);
     2319
    25012320    if (does_file_exist("/PAUSE")) {
    25022321        popup_and_OK
     
    25102329        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    25112330    }
    2512     paranoid_free(biggies_whose_EXATs_we_should_set);
    25132331    paranoid_free(pathname_of_last_biggie_restored);
    25142332    paranoid_free(biggie_fname);
    25152333    paranoid_free(biggie_cksum);
    2516     paranoid_free(xattr_fname);
    2517     paranoid_free(acl_fname);
    25182334    paranoid_free(tmp);
    25192335    return (retval);
     
    25392355 * @return 0 for success, or the number of filesets that failed.
    25402356 */
    2541 int
    2542 restore_all_tarballs_from_stream(struct s_node *filelist)
     2357int restore_all_tarballs_from_stream(struct s_node *filelist)
    25432358{
    25442359    int retval = 0;
     
    25492364
    25502365  /** malloc **/
    2551     char *tmp;
     2366    char *tmp = NULL;
    25522367    char *mds = NULL;
    2553     char *progress_str;
     2368    char *progress_str = NULL;
    25542369    char *tmp_fname;
    2555     char *xattr_fname;
    2556     char *acl_fname;
     2370    char *xattr_fname = NULL;
     2371    char *acl_fname = NULL;
    25572372
    25582373    long long tmp_size;
    25592374
    25602375    malloc_string(tmp);
    2561     malloc_string(progress_str);
    25622376    malloc_string(tmp_fname);
    25632377    assert(bkpinfo != NULL);
    2564     malloc_string(xattr_fname);
    2565     malloc_string(acl_fname);
    25662378    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
    25672379    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
     
    25742386    run_program_and_log_output("pwd", 5);
    25752387
    2576     sprintf(progress_str, "Restoring from media #%d",
    2577             g_current_media_number);
     2388    mr_asprintf(progress_str, "Restoring from media #%d", g_current_media_number);
    25782389    log_to_screen(progress_str);
    25792390    open_progress_form("Restoring from archives",
     
    25972408        update_progress_form(progress_str);
    25982409        if (g_getfattr) {
    2599             sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
    2600                 current_afioball_number);
     2410            mr_asprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
    26012411            unlink(xattr_fname);
    26022412        }
    26032413        if (g_getfacl) {
    2604             sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
    2605                 current_afioball_number);
     2414            mr_asprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
    26062415            unlink(acl_fname);
    26072416        }
    26082417        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
    26092418            log_it("Reading EXAT files from tape");
    2610             res = read_EXAT_files_from_tape(&tmp_size, tmp_fname,
    2611                                           &ctrl_chr, xattr_fname,
    2612                                           acl_fname);
     2419            res = read_EXAT_files_from_tape(&tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname);
    26132420        }
    26142421        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
    26152422            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
    26162423        }
    2617         sprintf(tmp,
    2618                 "Restoring from fileset #%ld (name=%s, size=%ld K)",
    2619                 current_afioball_number, tmp_fname, (long) tmp_size >> 10);
    2620         res =
    2621             restore_a_tarball_from_stream(tmp_fname,
    2622                                           current_afioball_number,
    2623                                           filelist, tmp_size, xattr_fname,
    2624                                           acl_fname);
     2424        log_msg(4, "Restoring from fileset #%ld (name=%s, size=%ld K)", current_afioball_number, tmp_fname, (long) tmp_size >> 10);
     2425        res = restore_a_tarball_from_stream(tmp_fname, current_afioball_number, filelist, tmp_size, xattr_fname, acl_fname);
    26252426        retval += res;
    26262427        if (res) {
    2627             sprintf(tmp, "Fileset %ld - errors occurred",
    2628                     current_afioball_number);
    2629             log_to_screen(tmp);
     2428            log_to_screen("Fileset %ld - errors occurred", current_afioball_number);
    26302429        }
    26312430        res =
     
    26382437        g_current_progress++;
    26392438        mds = media_descriptor_string(bkpinfo->backup_media_type),
    2640         sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
    2641                 current_afioball_number, mds,
    2642                 g_current_media_number);
     2439
     2440        mr_free(progress_str);
     2441        mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_afioball_number, mds, g_current_media_number);
    26432442        mr_free(mds);
    2644         res =
    2645             read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
     2443        res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
    26462444        if (g_getfattr) {
    26472445            unlink(xattr_fname);
     
    26512449        }
    26522450    }                           // next
     2451    mr_free(progress_str);
     2452    if (g_getfattr) {
     2453        mr_free(xattr_fname);
     2454    }
     2455    if (g_getfacl) {
     2456        mr_free(acl_fname);
     2457    }
     2458
    26532459    log_msg(1, "All done with afioballs");
    26542460    close_progress_form();
     
    26592465    }
    26602466    paranoid_free(tmp);
    2661     paranoid_free(progress_str);
    26622467    paranoid_free(tmp_fname);
    2663     paranoid_free(xattr_fname);
    2664     paranoid_free(acl_fname);
    26652468    return (retval);
    26662469}
     
    26892492    char *cwd;
    26902493    char *newpath;
    2691     char *tmp;
     2494    char *tmp = NULL;
    26922495    assert(bkpinfo != NULL);
    26932496
    26942497    malloc_string(cwd);
    26952498    malloc_string(newpath);
    2696     malloc_string(tmp);
    26972499    log_msg(2, "restore_everything() --- starting");
    26982500    g_current_media_number = 1;
     
    27002502        // FIXME
    27012503    }
    2702     sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
     2504    mr_asprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
    27032505    run_program_and_log_output(tmp, FALSE);
     2506    mr_free(tmp);
     2507
    27042508    log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
    27052509    if (chdir(bkpinfo->restore_path)) {
     
    27552559    paranoid_free(cwd);
    27562560    paranoid_free(newpath);
    2757     paranoid_free(tmp);
    27582561    return (resA + resB);
    27592562}
     
    27762579{
    27772580    log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
    2778     log_msg(0,
    2779             "DON'T PANIC! Mondorestore logs almost everything, so please ");
    2780     log_msg(0,
    2781             "don't break out in a cold sweat just because you see a few  ");
    2782     log_msg(0,
    2783             "error messages in the log. Read them; analyze them; see if  ");
    2784     log_msg(0,
    2785             "they are significant; above all, verify your backups! Please");
    2786     log_msg(0,
    2787             "attach a compressed copy of this log to any e-mail you send ");
    2788     log_msg(0,
    2789             "to the Mondo mailing list when you are seeking technical    ");
    2790     log_msg(0,
    2791             "support. Without it, we can't help you.            - DevTeam");
    2792     log_msg(0,
    2793             "------------------------------------------------------------");
    2794     log_msg(0,
    2795             "BTW, despite (or perhaps because of) the wealth of messages,");
    2796     log_msg(0,
    2797             "some users are inclined to stop reading this log.  If Mondo ");
    2798     log_msg(0,
    2799             "stopped for some reason, chances are it's detailed here.    ");
    2800     log_msg(0,
    2801             "More than likely there's a message at the very end of this  ");
    2802     log_msg(0,
    2803             "log that will tell you what is wrong.  Please read it!      ");
    2804     log_msg(0,
    2805             "------------------------------------------------------------");
     2581    log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please ");
     2582    log_msg(0, "don't break out in a cold sweat just because you see a few  ");
     2583    log_msg(0, "error messages in the log. Read them; analyze them; see if  ");
     2584    log_msg(0, "they are significant; above all, verify your backups! Please");
     2585    log_msg(0, "attach a compressed copy of this log to any e-mail you send ");
     2586    log_msg(0, "to the Mondo mailing list when you are seeking technical    ");
     2587    log_msg(0, "support. Without it, we can't help you.            - DevTeam");
     2588    log_msg(0, "------------------------------------------------------------");
     2589    log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages,");
     2590    log_msg(0, "some users are inclined to stop reading this log.  If Mondo ");
     2591    log_msg(0, "stopped for some reason, chances are it's detailed here.    ");
     2592    log_msg(0, "More than likely there's a message at the very end of this  ");
     2593    log_msg(0, "log that will tell you what is wrong.  Please read it!      ");
     2594    log_msg(0, "------------------------------------------------------------");
    28062595}
    28072596
     
    28182607    int retval = 0;
    28192608    int res;
    2820 //  int c;
    2821     char *tmp;
     2609    char *tmp = NULL;
    28222610
    28232611    struct mountlist_itself *mountlist;
    28242612    struct raidlist_itself *raidlist;
    28252613    struct s_node *filelist;
    2826     char *a, *b;
     2614    char *tmp1 = NULL;
     2615    char *tmp2 = NULL;
    28272616    bool run_postnuke = FALSE;
    28282617
     
    28382627
    28392628    g_loglevel = DEFAULT_MR_LOGLEVEL;
    2840     malloc_string(tmp);
    28412629
    28422630/* Configure global variables */
     
    28632651    }
    28642652
     2653    /* Init GUI */
     2654    setup_newt_stuff();         /* call newtInit and setup screen log */
     2655
    28652656    malloc_libmondo_global_strings();
    28662657
    28672658    strcpy(g_mondo_home,
    28682659           call_program_and_get_last_line_of_output("which mondorestore"));
    2869     /*
    2870     sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
    2871     make_hole_for_dir(g_tmpfs_mountpt);
    2872     */
    28732660    g_current_media_number = 1; // precaution
    28742661
    28752662    run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
    28762663
    2877     malloc_string(a);
    2878     malloc_string(b);
    28792664    setup_MR_global_filenames();    // malloc() and set globals, using bkpinfo->tmpdir etc.
    28802665    bkpinfo->backup_media_type = none;  // in case boot disk was made for one backup type but user wants to restore from another backup type
     
    28972682
    28982683    /* Backup original mountlist.txt */
    2899     sprintf(tmp, "%s.orig", g_mountlist_fname);
     2684    mr_asprintf(tmp, "%s.orig", g_mountlist_fname);
    29002685    if (!does_file_exist(g_mountlist_fname)) {
    2901         log_msg(2,
    2902                 "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
    2903                 __LINE__, g_mountlist_fname);
     2686        log_msg(2, "%ld: Warning - g_mountlist_fname (%s) does not exist yet", __LINE__, g_mountlist_fname);
    29042687    } else if (!does_file_exist(tmp)) {
    2905         sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
    2906                 g_mountlist_fname);
     2688        mr_free(tmp);
     2689        mr_asprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, g_mountlist_fname);
    29072690        run_program_and_log_output(tmp, FALSE);
    29082691    }
     2692    mr_free(tmp);
    29092693
    29102694    /* Init directories */
     
    29122696    make_hole_for_dir("/tmp/tmpfs");    /* just in case... */
    29132697    run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
    2914     /*
    2915     run_program_and_log_output("ln -sf /var/log/mondo-archive.log /tmp/mondorestore.log",
    2916          FALSE);
    2917          */
    29182698
    29192699    run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
    29202700
    2921     /* Init GUI */
    2922     setup_newt_stuff();         /* call newtInit and setup screen log */
    29232701    welcome_to_mondorestore();
    29242702    if (bkpinfo->disaster_recovery) {
     
    29542732    }
    29552733
    2956     if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
    2957         if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
    2958             paranoid_system("mount " MNT_CDROM);
    2959         }
    2960         bkpinfo->compression_level = 1;
    2961         g_current_media_number = 2;
    2962         strcpy(bkpinfo->restore_path, "/tmp/TESTING");
    2963         bkpinfo->backup_media_type = dvd;
    2964         open_progress_form("Reassembling /dev/hda1",
    2965                            "Shark is a bit of a silly person.",
    2966                            "Please wait. This may take some time.",
    2967                            "", 1999);
    2968         paranoid_system("rm -Rf /tmp/*pih*");
    2969 
    2970         restore_a_biggiefile_from_CD(42, NULL, tmp);
    2971     }
    2972 
    29732734    if (argc == 5 && strcmp(argv[1], "--common") == 0) {
    29742735        g_loglevel = 6;
     
    29812742        // BERLIOS: /usr/lib ???
    29822743        toggle_path_selection(filelist, "/usr/share", TRUE);
    2983 //      show_filelist(filelist);
    29842744        save_filelist(filelist, "/tmp/out.txt");
    2985 //      finish(0);
    2986 //      toggle_path_selection (filelist, "/root/stuff", TRUE);
    2987         strcpy(a, argv[3]);
    2988         strcpy(b, argv[4]);
    2989 
    2990         res = save_filelist_entries_in_common(a, filelist, b, FALSE);
     2745        mr_asprintf(tmp1, "%s", argv[3]);
     2746        mr_asprintf(tmp2, "%s", argv[4]);
     2747
     2748        res = save_filelist_entries_in_common(tmp1, filelist, tmp2, FALSE);
     2749        mr_free(tmp1);
     2750        mr_free(tmp2);
     2751
    29912752        free_filelist(filelist);
    29922753        printf("res = %d", res);
     
    30962857        log_msg(2, "Still here. Yay.");
    30972858        if ((strlen(bkpinfo->tmpdir) > 0) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) {
    3098             sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
     2859            mr_asprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
    30992860            run_program_and_log_output(tmp, FALSE);
     2861            mr_free(tmp);
    31002862        }
    31012863        unmount_boot_if_necessary();    /* for Gentoo users */
     
    31152877        // BCO:To be reviewed
    31162878        if ((bkpinfo->restore_mode == compare) || (bkpinfo->restore_mode == nuke)) {
    3117             if (bkpinfo->backup_media_type == netfs
    3118                 && !is_this_device_mounted(bkpinfo->netfs_mount)) {
     2879            if ((bkpinfo->backup_media_type == netfs) && bkpinfo->netfs_mount && !is_this_device_mounted(bkpinfo->netfs_mount)) {
    31192880                log_msg(1, "Mounting remote %s dir", bkpinfo->netfs_proto);
    31202881                sprintf(bkpinfo->isodir, "/tmp/isodir");
     
    31222883                if (strstr(bkpinfo->netfs_proto, "sshfs")) {
    31232884                    if (bkpinfo->netfs_user) {
    3124                         sprintf(tmp, "sshfs -o ro %s@%s /tmp/isodir",
    3125                             bkpinfo->netfs_user,bkpinfo->netfs_mount);
     2885                        mr_asprintf(tmp, "sshfs -o ro %s@%s /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount);
    31262886                    } else {
    3127                         sprintf(tmp, "sshfs -o ro %s /tmp/isodir",
    3128                             bkpinfo->netfs_mount);
     2887                        mr_asprintf(tmp, "sshfs -o ro %s /tmp/isodir", bkpinfo->netfs_mount);
    31292888                    }
    31302889                } else  {
    31312890                    if (strstr(bkpinfo->netfs_proto, "smbfs")) {
    31322891                        if (bkpinfo->netfs_user) {
    3133                             sprintf(tmp, "mount -t cifs %s /tmp/isodir -o user=%s,nolock,ro ",
    3134                                 bkpinfo->netfs_mount,bkpinfo->netfs_user);
     2892                            mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o user=%s,nolock,ro ", bkpinfo->netfs_mount,bkpinfo->netfs_user);
    31352893                        } else {
    3136                             sprintf(tmp, "mount -t cifs %s /tmp/isodir -o nolock,ro ",
    3137                                 bkpinfo->netfs_mount);
     2894                            mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o nolock,ro ", bkpinfo->netfs_mount);
    31382895                        }
    31392896                    } else {
    31402897                        if (bkpinfo->netfs_user) {
    3141                             sprintf(tmp, "mount %s@%s -o nolock,ro /tmp/isodir",
    3142                                 bkpinfo->netfs_user,bkpinfo->netfs_mount);
     2898                            mr_asprintf(tmp, "mount %s@%s -o nolock,ro /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount);
    31432899                        } else {
    3144                             sprintf(tmp, "mount %s -o nolock,ro /tmp/isodir",
    3145                                 bkpinfo->netfs_mount);
     2900                            mr_asprintf(tmp, "mount %s -o nolock,ro /tmp/isodir", bkpinfo->netfs_mount);
    31462901                        }
    31472902                    }
    31482903                }
    31492904                run_program_and_log_output(tmp, 1);
     2905                mr_free(tmp);
    31502906            }
    31512907        }
    31522908
    31532909        if (retval) {
    3154             log_to_screen
    3155                 ("Warning - load_raidtab_into_raidlist returned an error");
     2910            log_to_screen("Warning - load_raidtab_into_raidlist returned an error");
    31562911        }
    31572912
     
    32052960                                "Run complete. Please remove media and reboot.");
    32062961        } else {
    3207             run_program_and_log_output("sync", FALSE);
     2962            sync();
    32082963            if (is_this_device_mounted(MNT_CDROM)) {
    32092964                run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
     
    32422997      } else {
    32432998        log_msg(1, "Re-mounted partitions for post-nuke stuff");
    3244         sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
    3245             retval);
     2999        mr_asprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval);
    32463000        log_msg(2, "Calling '%s'", tmp);
    32473001        if ((res = run_program_and_log_output(tmp, 0))) {
    32483002          log_OS_error(tmp);
    32493003        }
     3004        mr_free(tmp);
    32503005        log_msg(1, "post-nuke returned w/ res=%d", res);
    32513006      }
     
    32633018    set_signals(FALSE);
    32643019    log_to_screen("Restore log (%s) copied to /var/log on your hard disk", MONDO_LOGFILE);
    3265     sprintf(tmp,
    3266             "Mondo-restore is exiting (retval=%d)                                      ",
    3267             retval);
    3268     log_to_screen(tmp);
    3269     sprintf(tmp, "umount -d %s", bkpinfo->isodir);
     3020    log_to_screen("Mondo-restore is exiting (retval=%d)                                      ", retval);
     3021
     3022    mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir);
    32703023    run_program_and_log_output(tmp, 5);
     3024    mr_free(tmp);
     3025
    32713026    paranoid_free(mountlist);
    32723027    paranoid_free(raidlist);
     
    32753030    }                           // for b0rken distros
    32763031    if (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL) {
    3277         sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
     3032        mr_asprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
    32783033        paranoid_system(tmp);
     3034        mr_free(tmp);
    32793035    }
    32803036    paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
    32813037    free_libmondo_global_strings(); // it's fine to have this here :) really :)
    3282     paranoid_free(a);
    3283     paranoid_free(b);
    3284     paranoid_free(tmp);
    32853038
    32863039    unlink("/tmp/filelist.full");
  • branches/3.2/mondo/src/mondorestore/mr-externs.h

    r3158 r3193  
    99#define BIGGIELIST MNT_CDROM"/archives/biggielist.txt"
    1010#define ARCHIVES_PATH MNT_CDROM"/archives"
     11#define BIGGIELIST ARCHIVES_PATH"/biggielist.txt"
    1112
    1213#ifdef __FreeBSD__
     
    7980extern int verify_tape_backups();
    8081extern char which_restore_mode(void);
    81 extern int which_format_command_do_i_need(char *, char *);
    8282extern int write_cfg_var(char *, char *, char *);
    8383extern void wrong_marker(int, int);
Note: See TracChangeset for help on using the changeset viewer.