Changeset 45 in MondoRescue for trunk/mondo/mondo/common/libmondo-raid.c


Ignore:
Timestamp:
Oct 5, 2005, 12:51:47 AM (19 years ago)
Author:
bcornec
Message:

asprint and getline now added

File:
1 edited

Legend:

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

    r43 r45  
    1 /* subroutines for handling RAID
    2    $Id$
     1/* $Id$
     2   subroutines for handling RAID
    33*/
    44
     
    4848
    4949    if (raidno == -1) {
    50         asprintf(&command, "cat /proc/mdstat | grep \"linear\" > /dev/null 2> /dev/null");
     50        asprintf(&command,
     51                 "cat /proc/mdstat | grep \"linear\" > /dev/null 2> /dev/null");
    5152    } else {
    52         asprintf(&command, "cat /proc/mdstat | grep \"raid%d\" > /dev/null 2> /dev/null", raidno);
     53        asprintf(&command,
     54                 "cat /proc/mdstat | grep \"raid%d\" > /dev/null 2> /dev/null",
     55                 raidno);
    5356    }
    5457    log_it("Is raid %d registered? Command = '%s'", raidno, command);
     
    6265#endif
    6366}
     67
    6468
    6569/**
     
    378382int get_next_raidtab_line(FILE * fin, char *label, char *value)
    379383{
    380     char *incoming;
     384    char *incoming = NULL;
    381385    char *p;
     386    size_t n = 0;
    382387
    383388    assert(fin != NULL);
     
    390395    }
    391396
    392     malloc_string(incoming);
    393     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    394          fgets(incoming, MAX_STR_LEN - 1, fin)) {
     397    for (getline(&incoming, &n, fin); !feof(fin);
     398         getline(&incoming, &n, fin)) {
    395399        strip_spaces(incoming);
    396400        p = strchr(incoming, ' ');
     
    555559    int v;
    556560
    557     malloc_string(label);
    558     malloc_string(value);
    559561    assert(raidlist != NULL);
    560562    assert_string_is_neither_NULL_nor_zerolength(fname);
     
    563565        log_it("Raidtab is very small or non-existent. Ignoring it.");
    564566        raidlist->entries = 0;
    565         paranoid_free(label);
    566         paranoid_free(value);
    567567        return (0);
    568568    }
    569569    if (!(fin = fopen(fname, "r"))) {
    570570        log_it("Cannot open raidtab");
    571         paranoid_free(label);
    572         paranoid_free(value);
    573571        return (1);
    574572    }
    575573    items = 0;
    576574    log_it("Loading raidtab...");
     575    malloc_string(label);
     576    malloc_string(value);
    577577    get_next_raidtab_line(fin, label, value);
    578578    while (!feof(fin)) {
     
    671671        if (!disklist) {
    672672            asprintf(&tmp,
    673                     "Ignoring '%s %s' pair of disk %s", labelB, valueB,
    674                     label);
     673                     "Ignoring '%s %s' pair of disk %s", labelB, valueB,
     674                     label);
    675675            log_it(tmp);
    676676            paranoid_free(tmp);
     
    904904    char *tmp;
    905905    char *stub;
    906     char *incoming;
     906    char *incoming = NULL;
    907907    char *raid_devname;
    908908    char *p, *q, *r;
    909909    int diskno;
     910    size_t n = 0;
    910911
    911912    malloc_string(incoming);
     
    915916    }
    916917    mdstat->entries = 0;
    917     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    918          fgets(incoming, MAX_STR_LEN - 1, fin)) {
     918    for (getline(&incoming, &n, fin); !feof(fin);
     919         getline(&incoming, &n, fin)) {
    919920        p = incoming;
    920921        if (*p != 'm' && *(p + 1) == 'm') {
     
    964965            asprintf(&tmp, "/dev/%s", stub);
    965966            paranoid_free(stub);
     967
    966968            log_msg(8, "/dev/md%d : disk#%d : %s (%d)",
    967969                    mdstat->el[mdstat->entries].md, diskno, tmp,
    968970                    mdstat->el[mdstat->entries].disks.el[diskno].index);
    969             strcpy(mdstat->el[mdstat->entries].disks.el[diskno].device, tmp);
     971            strcpy(mdstat->el[mdstat->entries].disks.el[diskno].device,
     972                   tmp);
    970973            paranoid_free(tmp);
     974
    971975            while (*p != ' ' && *p) {
    972976                p++;
     
    979983// next line --- skip it
    980984        if (!feof(fin)) {
    981             fgets(incoming, MAX_STR_LEN - 1, fin);
     985            getline(&incoming, &n, fin);
    982986        } else {
    983987            continue;
     
    985989// next line --- the 'progress' line
    986990        if (!feof(fin)) {
    987             fgets(incoming, MAX_STR_LEN - 1, fin);
     991            getline(&incoming, &n, fin);
    988992        } else {
    989993            continue;
     
    10421046
    10431047
    1044 
    10451048/* @} - end of raidGroup */
Note: See TracChangeset for help on using the changeset viewer.