diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-04-29 15:49:15 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-04-29 15:49:15 +0200 |
commit | 2945f6199eb2652bd8092367ae456dc0e49fb76d (patch) | |
tree | d77c66c0e5206b9a9f3439c29de6c4c65d12e1a4 /util/isensor.c | |
parent | 563deb61bf7f474ef6aa89f2038457af54eed0c1 (diff) | |
parent | b18f5bf2db0fba2e7e539f68645836036d940d26 (diff) |
New upstream release 2.9.6
Diffstat (limited to 'util/isensor.c')
-rw-r--r-- | util/isensor.c | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/util/isensor.c b/util/isensor.c index 6ce290d..e5a80e0 100644 --- a/util/isensor.c +++ b/util/isensor.c @@ -247,7 +247,7 @@ char *decode_entity_id(int id) { * Global Data ************************/ static char *progname = "isensor"; -static char *progver = "2.95"; +static char *progver = "2.96"; #ifdef WIN32 static char savefile[] = "%ipmiutildir%\\thresholds.cmd"; #else @@ -1354,6 +1354,9 @@ int get_sdr_file(char *sdrfile, uchar **sdrlist) num = 0; while (fgets(buff, 255, fp)) { num++; } if (fdebug) printf("Reading %d SDRs from file %s\n",num,sdrfile); + if ((psdrcache != NULL) && (nsdrs > 0)) { /*already have sdrcache*/ + printf("get_sdr_file: Already have cache\n"); /*++++*/ + } sdrbuf = malloc(num * SDR_SZ); if (sdrbuf == NULL) { fclose(fp); @@ -1402,8 +1405,10 @@ int get_sdr_cache(uchar **pret) if ((psdrcache != NULL) && (nsdrs > 0)) { /*already have sdrcache*/ *pret = psdrcache; if (fdebug) printf("get_sdr_cache: already have cache (%p)\n",*pret); + printf("get_sdr_cache: Already have cache\n"); /*++++*/ return(0); } + else printf("get_sdr_cache: Allocating cache\n"); /*++++*/ rv = GetSDRRepositoryInfo(&n,&fdevsdrs); if (rv != 0) return(rv); @@ -1434,6 +1439,12 @@ int get_sdr_cache(uchar **pret) if (rv == 0xC5) { set_reserve(1); i--; } /*retry*/ else break; } else { /*success*/ + /* if sdrlen!=len, adjust */ + if ((len > 5) && (len != (psdr[4] + 5)) ) { + if (fdebug) printf("SDR[%x] adjust len from %d to %d\n", + recid,psdr[4]+5,len); + psdr[4] = len - 5; + } asz += len; if (recnext == recid) recid = 0xffff; else recid = recnext; @@ -1451,19 +1462,23 @@ int get_sdr_cache(uchar **pret) int find_nsdrs(uchar *pcache) { int num = 0; - int asz = 0; + ulong asz = 0; int i, len; uchar *sdr; ushort recid; if (pcache == NULL) return(num); - for (i = 0; asz < sz_sdrs; i++) + for (i = 0; (int)asz < sz_sdrs; i++) { sdr = &pcache[asz]; + if (sdr[2] != 0x51) { /* Dell SDR length error */ + printf("SDR[%x] length error at %ld\n",recid,asz); + sdr = &pcache[++asz]; /*try it if off-by-one*/ + } len = sdr[4] + 5; recid = sdr[0] + (sdr[1] << 8); + if (fdebug) printf("SDR[%x] len=%d i=%d offset=%lx\n",recid,len,i,asz); asz += len; - if (fdebug) printf("SDR[%x] len=%d i=%d\n", recid,len,i); } num = i; return(num); @@ -1565,6 +1580,8 @@ int find_sdr_next(uchar *psdr, uchar *pcache, ushort id) { // sdr = &pcache[i * SDR_SZ]; sdr = &pcache[asz]; + if (sdr[2] != 0x51) /* Dell SDR off-by-one error */ + sdr = &pcache[++asz]; len = sdr[4] + 5; recid = sdr[0] + (sdr[1] << 8); asz += len; @@ -2974,14 +2991,15 @@ int read_sdr_binfile(char *binfile, uchar **pbufret, int *buflen) } } #endif - fp = fopen(binfile,"r"); + fp = fopen(binfile,"rb"); if (fp == NULL) { ret = get_LastError(); printf("Cannot open file %s, error %d\n",binfile,ret); return(ret); } + fseek(fp, 0L, SEEK_SET); #ifndef WIN32 - { + { /*not windows but Linux, etc.*/ struct stat st; /* use fstat to get file size and allocate buffer */ ret = fstat(fileno(fp), &st); @@ -2993,15 +3011,17 @@ int read_sdr_binfile(char *binfile, uchar **pbufret, int *buflen) } } #endif - // len = nsdrs * SDR_SZ; /*estimate max size for n sdrs*/ + /* Could estimate size for nsdrs*SDR_SZ, but we don't yet know nsdrs. + * It is better to use the real file size detected above. */ sz_sdrs = len; pbuf = malloc(len); - if (fdebug) printf("restore: malloc(%d) pbuf=%p\n",len,pbuf); + if (fdebug) printf("sdr_binfile: malloc(%d) pbuf=%p\n",len,pbuf); if (pbuf == NULL) { ret = -1; fclose(fp); return(ret); } + psdrcache = pbuf; /*ok, so proceed with restore*/ ret = 0; len = (int)fread(pbuf, 1, sz_sdrs, fp); @@ -3009,6 +3029,12 @@ int read_sdr_binfile(char *binfile, uchar **pbufret, int *buflen) ret = get_LastError(); printf("Error %d reading file %s\n",ret,binfile); sz_sdrs = 0; /*for safety*/ + } else if (len < sz_sdrs) { + /* Show error if this happens in Windows */ + ret = get_LastError(); + printf("truncated fread(%s): attempted %d, got %d, error %d\n", + binfile,sz_sdrs,len,ret); + ret = 0; /*try to keep going*/ } fclose(fp); if (fdebug) { @@ -3339,7 +3365,7 @@ int i_sensor(int argc, char **argv) int len; ret = get_sdr_cache(&pbuf); if (ret == 0) { - fp = fopen(binfile,"w"); + fp = fopen(binfile,"wb"); if (fp == NULL) { ret = get_LastError(); printf("Cannot open file %s, error %d\n",binfile,ret); @@ -3439,6 +3465,10 @@ int i_sensor(int argc, char **argv) recnext = sdrdata[0] + (sdrdata[1] << 8); /*same as recid*/ if (fdebug) printf("find_sdr_next(%04x): ret = %d, next=%04x\n", recid,ret,recnext); + if (recid > 0 && recnext == 0) { + if (fdebug) printf("Error recid=%04x recnext=%04x\n",recid,recnext); + ret = 0; break; + } sz = sdrdata[4] + 5; } else { ret = GetSDR(recid,&recnext,sdrdata,sizeof(sdrdata),&sz); |