Changeset 3193


Ignore:
Timestamp:
Sep 29, 2013, 9:31:34 AM (5 years ago)
Author:
bruno
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 {