[PATCH 2/2] i2c-tools: only try /dev/i2c/* if opening /dev/i2c-* fails with ENOENT
Bartosz Golaszewski
bartekgola at gmail.com
Tue Apr 21 12:29:22 UTC 2015
Trying to access /dev/i2c/* on every error after opening /dev/i2c-* can
mislead users who e.g. don't have root access. Instead of bailing-out
with "permission denied" we currently print "no such file or directory".
Fix it by checking for ENOENT if the first call to open() fails.
Upstream i2cdetect tries to get any info it can from /sys and /proc even
when invoked by an unprivileged user, but we don't want to add unnecessary
bloat.
Signed-off-by: Bartosz Golaszewski <bartekgola at gmail.com>
---
miscutils/i2c_tools.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c
index a5b6721..d32f3f5 100644
--- a/miscutils/i2c_tools.c
+++ b/miscutils/i2c_tools.c
@@ -379,8 +379,12 @@ static int i2c_dev_open(int i2cbus)
sprintf(filename, "/dev/i2c-%d", i2cbus);
fd = open(filename, O_RDWR);
if (fd < 0) {
- filename[8] = '/'; /* change to "/dev/i2c/%d" */
- fd = xopen(filename, O_RDWR);
+ if (errno == ENOENT) {
+ filename[8] = '/'; /* change to "/dev/i2c/%d" */
+ fd = xopen(filename, O_RDWR);
+ } else {
+ bb_perror_msg_and_die("can't open '%s'", filename);
+ }
}
return fd;
--
2.1.4
More information about the busybox
mailing list