Changeset 1174 in MondoRescue


Ignore:
Timestamp:
Feb 16, 2007, 1:22:49 PM (17 years ago)
Author:
Bruno Cornec
Message:

Merger memory management from trunk for libmondo-raid.c
Additional check for mr_allocstr

Location:
branches/stable/mondo/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-raid.c

    r1172 r1174  
    1 /* libmondo-raid.c                                                subroutines for handling RAID
    2    $Id$
     1/* $Id$
     2   subroutines for handling RAID
    33*/
    44
     
    1010
    1111#include "my-stuff.h"
     12#include "mr_str.h"
     13#include "mr_mem.h"
     14#include "mr_msg.h"
     15
    1216#include "mondostructures.h"
    13 #include "libmondo-gui-EXT.h"
     17#include "newt-specific-EXT.h"
    1418#include "libmondo-files-EXT.h"
    1519#include "libmondo-tools-EXT.h"
    1620#include "libmondo-string-EXT.h"
    1721#include "libmondo-raid.h"
    18 #include "mr_str.h"
    19 #include "mr_mem.h"
    20 #include "mr_msg.h"
    2122
    2223#ifdef __FreeBSD__
     
    4748#else
    4849    /*@ buffer ********************************************************** */
    49     char *command;
    50     int res;
    51 
    52     command = mr_malloc(MAX_STR_LEN * 2);
    53     strcpy(command, "grep \" /proc/mdstat");
     50    char *command = NULL;
     51    int res = 0;
     52
    5453    if (raidno == -1) {
    55         strcat(command, "linear");
     54        mr_asprintf(&command,
     55                 "grep \"linear\" /proc/mdstat > /dev/null 2> /dev/null");
    5656    } else {
    57         sprintf(command + strlen(command), "raid%d", raidno);
    58     }
    59     strcat(command, "\" > /dev/null 2> /dev/null");
     57        mr_asprintf(&command,
     58                 "grep \"raid%d\" /proc/mdstat > /dev/null 2> /dev/null",
     59                 raidno);
     60    }
    6061    log_it("Is raid %d registered? Command = '%s'", raidno, command);
    6162    res = system(command);
     
    7071
    7172
    72 
    73 
    74 
    75 
    7673/**
    7774 * Search for @p device in @p disklist.
     
    10198    }
    10299}
    103 
    104 
    105 
    106 
    107 
    108 
    109 
    110100
    111101/**
     
    192182{
    193183    /*@ buffers ***************************************************** */
    194     char *sz_value;
    195 
    196     malloc_string(sz_value);
     184    char *sz_value = NULL;
     185
    197186    assert(raidrec != NULL);
    198187    assert(label != NULL);
    199188
    200     sprintf(sz_value, "%d", value);
     189    mr_asprintf(&sz_value, "%d", value);
    201190    strcpy(raidrec->additional_vars.el[lino].label, label);
    202191    strcpy(raidrec->additional_vars.el[lino].value, sz_value);
     
    204193}
    205194#endif
    206 
    207 
    208 
    209 
    210 
    211 
    212 
    213195
    214196#ifdef __FreeBSD__
     
    335317#ifdef __FreeBSD__
    336318    int i, j;
     319    char *org = NULL;
    337320
    338321    fprintf(fout, "\nvolume %s\n", raidrec->volname);
    339322    for (i = 0; i < raidrec->plexes; ++i) {
    340         char org[24];
    341323        switch (raidrec->plex[i].raidlevel) {
    342324        case -1:
    343             strcpy(org, "concat");
     325            mr_asprintf(&org, "concat");
    344326            break;
    345327        case 0:
    346             strcpy(org, "striped");
     328            mr_asprintf(&org, "striped");
    347329            break;
    348330        case 5:
    349             strcpy(org, "raid5");
     331            mr_asprintf(&org, "raid5");
    350332            break;
    351333        }
    352334        fprintf(fout, "  plex org %s", org);
     335        mr_free(org);
     336
    353337        if (raidrec->plex[i].raidlevel != -1) {
    354338            fprintf(fout, " %ik", raidrec->plex[i].stripesize);
     
    425409 * @return 0 if the line was read and stored successfully, 1 if we're at end of file.
    426410 */
    427 int get_next_raidtab_line(FILE * fin, char *label, char *value)
    428 {
    429     char *incoming;
    430     char *p;
    431 
    432     malloc_string(incoming);
     411int get_next_raidtab_line(FILE *fin, char *label, char *value)
     412{
     413    char *incoming = NULL;
     414    char *p = NULL;
     415    size_t n = 0;
     416
    433417    assert(fin != NULL);
    434418    assert(label != NULL);
     
    437421    label[0] = value[0] = '\0';
    438422    if (feof(fin)) {
    439         mr_free(incoming);
    440423        return (1);
    441424    }
    442     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    443          fgets(incoming, MAX_STR_LEN - 1, fin)) {
     425    for (mr_getline(&incoming, &n, fin); !feof(fin);
     426         mr_getline(&incoming, &n, fin)) {
    444427        mr_strip_spaces(incoming);
    445428        p = strchr(incoming, ' ');
     
    456439        return (0);
    457440    }
     441    mr_free(incoming);
    458442    return (1);
    459443}
    460 
    461444
    462445
     
    471454                               char *fname)
    472455{
    473     FILE *fin;
    474     char *tmp;
    475     int items;
    476 
    477     malloc_string(tmp);
     456    FILE *fin = NULL;
     457    int items = 0;
     458
    478459    raidlist->spares.entries = 0;
    479460    raidlist->disks.entries = 0;
     
    481462        log_it("Raidtab is very small or non-existent. Ignoring it.");
    482463        raidlist->entries = 0;
    483         mr_free(tmp);
    484464        return (0);
    485465    }
    486466    if (!(fin = fopen(fname, "r"))) {
    487467        log_it("Cannot open raidtab");
    488         mr_free(tmp);
    489468        return (1);
    490469    }
     
    523502            }
    524503        } else if (!strcmp(argv[0], "volume")) {
    525             char *volname;
     504            char *volname = NULL;
    526505            if (argc < 2)
    527506                continue;
     
    532511        } else if (!strcmp(argv[0], "plex")) {
    533512            int raidlevel, stripesize;
    534             char *org = 0;
    535             char **tmp = 0;
     513            char *org = NULL;
     514            char **tmp = NULL;
    536515            if (argc < 3)
    537516                continue;
     
    570549        } else if ((!strcmp(argv[0], "sd"))
    571550                   || (!strcmp(argv[0], "subdisk"))) {
    572             char *drive = 0;
     551            char *drive = NULL;
    573552            if (argc < 3)
    574553                continue;
     
    589568    fclose(fin);
    590569    log_it("Raidtab loaded successfully.");
    591     sprintf(tmp, "%d RAID devices in raidtab", raidlist->entries);
    592     log_it(tmp);
    593     mr_free(tmp);
     570    log_it("%d RAID devices in raidtab", raidlist->entries);
    594571    return (0);
    595572}
     
    601578                               char *fname)
    602579{
    603     FILE *fin;
    604     char *tmp;
    605     char *label;
    606     char *value;
     580    FILE *fin = NULL;
     581    char *label = NULL;
     582    char *value = NULL;
    607583    int items;
    608584    int v;
    609585
    610     malloc_string(tmp);
    611     malloc_string(label);
    612     malloc_string(value);
    613586    assert(raidlist != NULL);
    614587    assert_string_is_neither_NULL_nor_zerolength(fname);
     
    617590        log_it("Raidtab is very small or non-existent. Ignoring it.");
    618591        raidlist->entries = 0;
    619         mr_free(tmp);
    620         mr_free(label);
    621         mr_free(value);
    622592        return (0);
    623593    }
    624594    if (!(fin = fopen(fname, "r"))) {
    625595        log_it("Cannot open raidtab");
    626         mr_free(tmp);
    627         mr_free(label);
    628         mr_free(value);
    629596        return (1);
    630597    }
     
    642609            v++;
    643610            get_next_raidtab_line(fin, label, value);
    644             log_it(tmp);
    645611        }
    646612        raidlist->el[items].additional_vars.entries = v;
     
    662628    mr_msg(1, "Raidtab loaded successfully.");
    663629    mr_msg(1, "%d RAID devices in raidtab", items);
    664     mr_free(tmp);
    665     mr_free(label);
    666     mr_free(value);
    667630    return (0);
    668631}
    669632#endif
    670 
    671 
    672 
    673 
    674 
    675 
    676633
    677634
     
    685642 */
    686643void
    687 process_raidtab_line(FILE * fin,
     644process_raidtab_line(FILE *fin,
    688645                     struct raid_device_record *raidrec,
    689646                     char *label, char *value)
     
    691648
    692649    /*@ add mallocs * */
    693     char *tmp;
    694     char *labelB;
    695     char *valueB;
    696 
    697     struct list_of_disks *disklist;
    698     int v;
    699 
    700     malloc_string(tmp);
     650    char *labelB = NULL;
     651    char *valueB = NULL;
     652
     653    struct list_of_disks *disklist = NULL;
     654    int v = 0;
     655
    701656    malloc_string(labelB);
    702657    malloc_string(valueB);
     
    748703        }
    749704        if (!disklist) {
    750             sprintf(tmp,
    751                     "Ignoring '%s %s' pair of disk %s", labelB, valueB,
     705            log_it("Ignoring '%s %s' pair of disk %s", labelB, valueB,
    752706                    label);
    753             log_it(tmp);
    754707        } else {
    755708            add_disk_to_raid_device(disklist, value, atoi(valueB));
    756709        }
     710        mr_free(labelB);
     711        mr_free(valueB);
    757712    } else {
    758713        v = raidrec->additional_vars.entries;
     
    761716        raidrec->additional_vars.entries = ++v;
    762717    }
    763     mr_free(tmp);
    764     mr_free(labelB);
    765     mr_free(valueB);
    766718}
    767719#endif
     
    792744
    793745
    794 
    795 
    796 
    797746#ifdef __FreeBSD__
    798747/**
     
    819768    static char *argv[64];
    820769    char **ap;
    821     char *line = (char *) mr_malloc(MAX_STR_LEN);
    822     (void) fgets(line, MAX_STR_LEN, f);
     770    char *line = NULL;
     771    size_t = 0;
     772    int lastpos = 0;
     773
     774    mr_getline(&line, &n, f);
    823775    if (feof(f)) {
    824776        log_it("[GNVCL] Uh... I reached the EOF.");
    825         return 0;
     777        return NULL;
    826778    }
    827779
     
    961913                    ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes?!?!");
    962914                popup_and_OK
    963                     ("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");
     915                    (_("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)"));
    964916                return size * sign * 1024 * 1024 * 1024 * 1024 * 1024 *
    965917                    1024 * 1024 * 1024;
     
    979931  const char delims[] = " ";
    980932
    981   FILE   *fin;
    982   int    row, i, index_min;
     933  FILE *fin = NULL;
     934  int row = 0;
     935  int i = 0;
     936  int index_min = 0;
    983937  int lastpos = 0;
    984938  size_t len = 0;
    985   char   *token;
     939  char *token = NULL;
    986940  char *string = NULL;
    987   char *pos;
    988   char type;
    989   char *strtmp;
     941  char *pos = NULL;
     942  char type = NULL;
     943  char *strtmp = NULL;
    990944
    991945  // open file
     
    1005959    // trim leading spaces
    1006960    pos = string;
    1007     while (*pos == ' ') pos += 1;
     961    while (*pos == ' ') pos++;
    1008962    mr_asprintf(&strtmp, pos);
    1009     strcpy(string, strtmp);
     963    mr_allocstr(string,strtmp);
    1010964    mr_free(strtmp);
    1011965    // if we have newline after only spaces, this is a blank line, update
     
    12351189
    12361190
    1237 
    12381191/* @} - end of raidGroup */
  • branches/stable/mondo/src/common/libmondo-stream.c

    r1123 r1174  
    1 /* libmondo-stream.c
    2    $Id$
     1/* $Id$
    32
    43...tools for talking to tapes, Monitas streams, etc.
    5 
    64*/
    75
    8 
    9 /**
     6/*
     7 *
    108 * @file
    119 * Functions for writing data to/reading data from streams (tape, CD stream, etc.)
    1210 */
     11
     12#include <unistd.h>
    1313
    1414#include "my-stuff.h"
    1515#include "mr_mem.h"
    1616#include "mr_msg.h"
     17
    1718#include "mondostructures.h"
    1819#include "libmondo-devices.h"
     
    2021#include "libmondo-string-EXT.h"
    2122#include "libmondo-files-EXT.h"
    22 #include "libmondo-gui-EXT.h"
     23#include "newt-specific-EXT.h"
    2324#include "libmondo-fork-EXT.h"
    2425#include "libmondo-tools-EXT.h"
  • branches/stable/mondo/src/lib/mr_mem.c

    r1156 r1174  
    8686void mr_allocstr_int(char *alloc, const char *orig, int line, const char *file) {
    8787
    88     mr_free_int((void **)&alloc, line, file);
     88    if (alloc != NULL) {
     89        mr_free_int((void **)&alloc, line, file);
     90    }
    8991    mr_asprintf_int(&alloc, line, file, orig);
    9092}
Note: See TracChangeset for help on using the changeset viewer.