From 86d41cfc961df174d1e396b5fea543ed0ca9184c Mon Sep 17 00:00:00 2001 From: "Mark D. Studebaker" Date: Sun, 16 Jul 2000 22:54:41 +0000 Subject: [PATCH] (mds) fix error reporting when you don't have permission to open /dev/i2c-x and /dev/i2cx doesn't exist. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@847 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 3 +++ prog/detect/i2cdetect.c | 21 +++++++++++++++++++-- prog/dump/i2cdump.c | 21 +++++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 5069c35d..f8848764 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,9 @@ ask CVS about it: for example: cvs diff -r V2-0-0 -r V2-0-1 -u +2.5.3 (2000????) + Programs i2cdetect, i2cdump: Improve error reporting + 2.5.2 (20000709) File sensors.conf.eg: Fix lm80 in8 calculation Module w83781d: W83783S no longer crashes on unloading diff --git a/prog/detect/i2cdetect.c b/prog/detect/i2cdetect.c index 5de5f49c..0a8af6f4 100644 --- a/prog/detect/i2cdetect.c +++ b/prog/detect/i2cdetect.c @@ -45,6 +45,7 @@ int main(int argc, char *argv[]) { char *end; int i,j,res,i2cbus,file; + int e1, e2; char filename1[20]; char filename2[20]; char *filename; @@ -71,9 +72,25 @@ int main(int argc, char *argv[]) sprintf(filename1,"/dev/i2c-%d",i2cbus); sprintf(filename2,"/dev/i2c%d",i2cbus); if ((file = open(filename1,O_RDWR)) < 0) { + e1 = errno; if ((file = open(filename2,O_RDWR)) < 0) { - fprintf(stderr,"Error: Could not open file `%s' or `%s': %s\n",filename1, - filename2,strerror(errno)); + e2 = errno; + if(e1 == ENOENT && e2 == ENOENT) { + fprintf(stderr,"Error: Could not open file `%s' or `%s': %s\n", + filename1,filename2,strerror(ENOENT)); + } + if (e1 != ENOENT) { + fprintf(stderr,"Error: Could not open file `%s' : %s\n", + filename1,strerror(e1)); + if(e1 == EACCES) + fprintf(stderr,"Run as root?\n"); + } + if (e2 != ENOENT) { + fprintf(stderr,"Error: Could not open file `%s' : %s\n", + filename2,strerror(e2)); + if(e2 == EACCES) + fprintf(stderr,"Run as root?\n"); + } exit(1); } else { filename = filename2; diff --git a/prog/dump/i2cdump.c b/prog/dump/i2cdump.c index 1fb0350a..6ef8e878 100644 --- a/prog/dump/i2cdump.c +++ b/prog/dump/i2cdump.c @@ -45,6 +45,7 @@ int main(int argc, char *argv[]) { char *end; int i,j,res,i2cbus,address,size,file; + int e1, e2; int bank = 0, bankreg = 0x4E; char filename1[20]; char filename2[20]; @@ -128,9 +129,25 @@ int main(int argc, char *argv[]) sprintf(filename1,"/dev/i2c-%d",i2cbus); sprintf(filename2,"/dev/i2c%d",i2cbus); if ((file = open(filename1,O_RDWR)) < 0) { + e1 = errno; if ((file = open(filename2,O_RDWR)) < 0) { - fprintf(stderr,"Error: Could not open file `%s' or `%s': %s\n",filename1, - filename2,strerror(errno)); + e2 = errno; + if(e1 == ENOENT && e2 == ENOENT) { + fprintf(stderr,"Error: Could not open file `%s' or `%s': %s\n", + filename1,filename2,strerror(ENOENT)); + } + if (e1 != ENOENT) { + fprintf(stderr,"Error: Could not open file `%s' : %s\n", + filename1,strerror(e1)); + if(e1 == EACCES) + fprintf(stderr,"Run as root?\n"); + } + if (e2 != ENOENT) { + fprintf(stderr,"Error: Could not open file `%s' : %s\n", + filename2,strerror(e2)); + if(e2 == EACCES) + fprintf(stderr,"Run as root?\n"); + } exit(1); } else { filename = filename2;