summaryrefslogtreecommitdiff
path: root/util/isensor.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/isensor.c')
-rw-r--r--util/isensor.c62
1 files changed, 40 insertions, 22 deletions
diff --git a/util/isensor.c b/util/isensor.c
index e5a80e0..6be2836 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.96";
+static char *progver = "2.97";
#ifdef WIN32
static char savefile[] = "%ipmiutildir%\\thresholds.cmd";
#else
@@ -1353,10 +1353,13 @@ int get_sdr_file(char *sdrfile, uchar **sdrlist)
/* determine number of SDRs by number of lines in the file */
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"); /*++++*/
- }
+ 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"); /*fdebug*/
+ free_sdr_cache(psdrcache); /*free previous sdrcache*/
+ }
+ }
sdrbuf = malloc(num * SDR_SZ);
if (sdrbuf == NULL) {
fclose(fp);
@@ -1405,10 +1408,9 @@ 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"); /*++++*/
+ else if (fdebug) printf("get_sdr_cache: Allocating cache\n");
rv = GetSDRRepositoryInfo(&n,&fdevsdrs);
if (rv != 0) return(rv);
@@ -1612,6 +1614,7 @@ int find_sdr_by_id(uchar *psdr, uchar *pcache, ushort id)
recid = sdr[0] + (sdr[1] << 8);
asz += len;
if (recid == id) { rv = 0; break; }
+ else if (id == 0) { rv = 0; break; } /* 0000 = first one */
}
if (rv == 0) memcpy(psdr,sdr,len);
return(rv);
@@ -2462,11 +2465,13 @@ ShowSDR(char *tag, uchar *sdr)
if (fdebug) printf("ShowSDR: len=%d, type=%x\n",len,sdr[3]);
memset(sens,0,4);
if (frawsdr || fdebug) {
+ /* raw is different than dump_buf */
printf("raw SDR: ");
for (i = 0; i < len; i++)
printf("%02x ",sdr[i]);
printf("\n");
}
+ strcpy(idstr,"INIT"); /*always set idstr to some initial string*/
switch(sdr[3])
{
case 0x01: /* Full sensor record */
@@ -2475,12 +2480,19 @@ ShowSDR(char *tag, uchar *sdr)
if (ioff > len) {
if (fdebug) printf("bad length: type=%x, len=%d, ioff=%d\n",
sdr[3],len,ioff);
- printf("Bad SDR Length, please apply the correct FRU/SDR diskette\n");
+ fprintf(stderr,"Bad SDR Length %d, please apply the correct FRU/SDR diskette\n",len);
return;
}
sens_cap = sdr[11]; /*sdr01->sens_capab*/
+ // ilen = (sdr[ioff] & 0x1f); /*sdr01->id_typelen*/
ilen = len - ioff;
+ if (fdebug) printf("SDR[%x] Full ioff=%d idTypLen=0x%02x ilen=%d\n",
+ sdr01->recid, ioff,sdr[ioff] ,ilen);
if (ilen >= sizeof(idstr)) ilen = sizeof(idstr) - 1;
+ if (ilen <= 0) { /*bug if true*/
+ fprintf(stderr,"Bad SDR Length %d, omits ID string\n",len);
+ ilen = 16; /*less than sizeof(idstr)*/
+ }
memcpy(idstr,&sdr[ioff],ilen);
for (i=ilen; i<16; i++) { idstr[i] = ' '; ilen++; }
idstr[ilen] = 0; /* stringify */
@@ -2580,7 +2592,7 @@ ShowSDR(char *tag, uchar *sdr)
if (ioff > len) {
if (fdebug) printf("bad length: type=%x, len=%d, ioff=%d\n",
sdr[3],len,ioff);
- printf("Bad SDR Length, please apply the correct FRU/SDR diskette\n");
+ fprintf(stderr,"Bad SDR Length, please apply the correct FRU/SDR diskette\n");
return;
}
sens_cap = sdr[11]; /*sdr02->sens_capab*/
@@ -2682,7 +2694,7 @@ ShowSDR(char *tag, uchar *sdr)
sdr02 = (SDR02REC *)sdr;
ioff = 17;
if (ioff > len) {
- printf("Bad SDR %x Length %d. Please apply the correct FRU/SDR diskette\n",
+ fprintf(stderr,"Bad SDR %x Length %d. Please apply the correct FRU/SDR diskette\n",
sdr02->recid, len);
return;
}
@@ -3065,7 +3077,7 @@ int i_sensor(int argc, char **argv)
uchar devrec[16];
int sz, i, j;
int fsetfound = 0;
- int iloop;
+ int iloop, irec;
int ipass, npass;
uchar *pset;
char *p;
@@ -3264,8 +3276,9 @@ int i_sensor(int argc, char **argv)
i = geteuid();
if (i > 1) {
printf("Not superuser (%d)\n", i);
- ret = ERR_NOT_ALLOWED;
- goto do_exit;
+ /* Show warning, but could be ok if /dev/ipmi0 is accessible */
+ //ret = ERR_NOT_ALLOWED;
+ //goto do_exit;
}
}
#endif
@@ -3454,10 +3467,13 @@ int i_sensor(int argc, char **argv)
{
if (fshowidx) recid = sensor_idx1;
else recid = 0;
+ irec = 0; /*first sdr record*/
while (recid != 0xffff)
{
if (fjumpstart) {
- ret = find_sdr_next(sdrdata,psdrcache,recid);
+ if (irec == 0) /*need sdr_by_id if fshowid recid>0*/
+ ret = find_sdr_by_id(sdrdata,psdrcache,recid);
+ else ret = find_sdr_next(sdrdata,psdrcache,recid);
if (ret != 0) { /*end of sdrs*/
if (fdebug) printf("find_sdr_next(%04x): ret = %d\n", recid,ret);
ret = 0; break;
@@ -3476,8 +3492,8 @@ int i_sensor(int argc, char **argv)
printf("GetSDR[%04x]: ret = %x, next=%x\n",recid,ret,recnext);
if (ret != 0) {
if (ret > 0) { /* ret is a completion code error */
- printf("%04x GetSDR error 0x%02x %s, rlen=%d\n",recid,ret,
- decode_cc((ushort)0,(uchar)ret),sz);
+ fprintf(stderr,"%04x GetSDR error 0x%02x %s, rlen=%d\n",
+ recid,ret,decode_cc((ushort)0,(uchar)ret),sz);
if (ret == 0xC5) { /* lost Reservation ID, retry */
/* This means that some other IPMI software has
* requested a Reservation before we finished, so
@@ -3488,7 +3504,8 @@ int i_sensor(int argc, char **argv)
printf("GetSDR[%04x]: ret = %x, next=%x\n",recid,ret,
recnext);
}
- } else printf("%04x GetSDR error %d, rlen = %d\n", recid,ret,sz);
+ } else fprintf(stderr,"%04x GetSDR error %d, rlen = %d\n",
+ recid,ret,sz);
if (sz < MIN_SDR_SZ) { /* don't have recnext, so abort */
break;
} /* else fall through & continue */
@@ -3559,7 +3576,7 @@ int i_sensor(int argc, char **argv)
{
ret = GetSDR(_recid,&_recnext,_sdrdata,sizeof(_sdrdata),&_sz);
if (ret != 0) {
- printf("%04x GetSDR error %d, rlen = %d\n",_recid,ret,_sz);
+ fprintf(stderr,"%04x GetSDR error %d, rlen = %d\n",_recid,ret,_sz);
break;
}
else if (_sz >= MIN_SDR_SZ)
@@ -3644,15 +3661,16 @@ int i_sensor(int argc, char **argv)
} /*endif ok, got full SDR */
NextSdr:
- if (fshowidx) {
- /* if we have already read the last in the range, done. */
- if (recid >= sensor_idxN) break; // recnext = 0xffff; // break;
- }
if (fjumpstart) recid = recnext;
else {
if (recnext == recid) recid = 0xffff; /*break;*/
else recid = recnext;
}
+ if (fshowidx) {
+ /* if we have already read the last in the range, done. */
+ if (recid >= sensor_idxN) break; // recnext = 0xffff; // break;
+ }
+ irec++;
} /*end while recid*/
if (fdoloop && (nloops > 1)) {
printf("\n"); /* output an empty separator line */