Changeset 847

Show
Ignore:
Timestamp:
07/17/00 00:54:41 (13 years ago)
Author:
mds
Message:

(mds) fix error reporting when you don't have permission to open

/dev/i2c-x and /dev/i2cx doesn't exist.

Location:
lm-sensors/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r842 r847  
    1313    for example: 
    1414      cvs diff -r V2-0-0 -r V2-0-1 -u 
     15 
     162.5.3 (2000????) 
     17  Programs i2cdetect, i2cdump: Improve error reporting 
    1518 
    16192.5.2 (20000709) 
  • lm-sensors/trunk/prog/detect/i2cdetect.c

    r827 r847  
    4646  char *end; 
    4747  int i,j,res,i2cbus,file; 
     48  int e1, e2; 
    4849  char filename1[20]; 
    4950  char filename2[20]; 
     
    7273  sprintf(filename2,"/dev/i2c%d",i2cbus); 
    7374  if ((file = open(filename1,O_RDWR)) < 0) { 
     75    e1 = errno; 
    7476    if ((file = open(filename2,O_RDWR)) < 0) { 
    75       fprintf(stderr,"Error: Could not open file `%s' or `%s': %s\n",filename1, 
    76               filename2,strerror(errno)); 
     77      e2 = errno; 
     78      if(e1 == ENOENT && e2 == ENOENT) { 
     79        fprintf(stderr,"Error: Could not open file `%s' or `%s': %s\n", 
     80                   filename1,filename2,strerror(ENOENT)); 
     81      } 
     82      if (e1 != ENOENT) { 
     83        fprintf(stderr,"Error: Could not open file `%s' : %s\n", 
     84                   filename1,strerror(e1)); 
     85        if(e1 == EACCES) 
     86          fprintf(stderr,"Run as root?\n"); 
     87      } 
     88      if (e2 != ENOENT) { 
     89        fprintf(stderr,"Error: Could not open file `%s' : %s\n", 
     90                   filename2,strerror(e2)); 
     91        if(e2 == EACCES) 
     92          fprintf(stderr,"Run as root?\n"); 
     93      } 
    7794      exit(1); 
    7895    } else { 
  • lm-sensors/trunk/prog/dump/i2cdump.c

    r830 r847  
    4646  char *end; 
    4747  int i,j,res,i2cbus,address,size,file; 
     48  int e1, e2; 
    4849  int bank = 0, bankreg = 0x4E; 
    4950  char filename1[20]; 
     
    129130  sprintf(filename2,"/dev/i2c%d",i2cbus); 
    130131  if ((file = open(filename1,O_RDWR)) < 0) { 
     132    e1 = errno; 
    131133    if ((file = open(filename2,O_RDWR)) < 0) { 
    132       fprintf(stderr,"Error: Could not open file `%s' or `%s': %s\n",filename1, 
    133               filename2,strerror(errno)); 
     134      e2 = errno; 
     135      if(e1 == ENOENT && e2 == ENOENT) { 
     136        fprintf(stderr,"Error: Could not open file `%s' or `%s': %s\n", 
     137                   filename1,filename2,strerror(ENOENT)); 
     138      } 
     139      if (e1 != ENOENT) { 
     140        fprintf(stderr,"Error: Could not open file `%s' : %s\n", 
     141                   filename1,strerror(e1)); 
     142        if(e1 == EACCES) 
     143          fprintf(stderr,"Run as root?\n"); 
     144      } 
     145      if (e2 != ENOENT) { 
     146        fprintf(stderr,"Error: Could not open file `%s' : %s\n", 
     147                   filename2,strerror(e2)); 
     148        if(e2 == EACCES) 
     149          fprintf(stderr,"Run as root?\n"); 
     150      } 
    134151      exit(1); 
    135152    } else {