diff options
author | Bartosz Golaszewski <bartekgola@gmail.com> | 2015-05-11 17:26:27 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-05-11 17:26:27 +0200 |
commit | 7ca5c51cc8c54f35b6265d815d8a8be19e0821b0 (patch) | |
tree | fdd1b8a7d22391c24b083f9846dc75dbad1fb319 /miscutils | |
parent | b2cca32a37b969cce3b3bce693708759d44d3d15 (diff) | |
download | busybox-w32-7ca5c51cc8c54f35b6265d815d8a8be19e0821b0.tar.gz busybox-w32-7ca5c51cc8c54f35b6265d815d8a8be19e0821b0.tar.bz2 busybox-w32-7ca5c51cc8c54f35b6265d815d8a8be19e0821b0.zip |
i2c-tools: only try /dev/i2c/* if opening /dev/i2c-* fails with ENOENT
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 trying open("/dev/i2c/%d") only if we got ENOENT.
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@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/i2c_tools.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index 2805cf3b0..7034dc9a8 100644 --- a/miscutils/i2c_tools.c +++ b/miscutils/i2c_tools.c | |||
@@ -379,8 +379,12 @@ static int i2c_dev_open(int i2cbus) | |||
379 | sprintf(filename, "/dev/i2c-%d", i2cbus); | 379 | sprintf(filename, "/dev/i2c-%d", i2cbus); |
380 | fd = open(filename, O_RDWR); | 380 | fd = open(filename, O_RDWR); |
381 | if (fd < 0) { | 381 | if (fd < 0) { |
382 | filename[8] = '/'; /* change to "/dev/i2c/%d" */ | 382 | if (errno == ENOENT) { |
383 | fd = xopen(filename, O_RDWR); | 383 | filename[8] = '/'; /* change to "/dev/i2c/%d" */ |
384 | fd = xopen(filename, O_RDWR); | ||
385 | } else { | ||
386 | bb_perror_msg_and_die("can't open '%s'", filename); | ||
387 | } | ||
384 | } | 388 | } |
385 | 389 | ||
386 | return fd; | 390 | return fd; |