diff options
author | Sami Kerola | 2017-07-04 22:43:56 +0200 |
---|---|---|
committer | Sami Kerola | 2017-08-30 21:32:49 +0200 |
commit | f806a238f7dea936cbc15ad91590c40ac27c2e8d (patch) | |
tree | 2089efa99a863a0398e5baa3813894b6e4ed4b17 /sys-utils/rfkill.c | |
parent | rfkill: use back and forward compatible test (diff) | |
download | kernel-qcow2-util-linux-f806a238f7dea936cbc15ad91590c40ac27c2e8d.tar.gz kernel-qcow2-util-linux-f806a238f7dea936cbc15ad91590c40ac27c2e8d.tar.xz kernel-qcow2-util-linux-f806a238f7dea936cbc15ad91590c40ac27c2e8d.zip |
rfkill: check id number refers to a device that exists
Earlier all commands happily accepted without detecting failure when
none-existing id number was used. For example:
$ rfkill block 2017; echo $?
0
The same input after this change looks following.
$ rfkill block 2017; echo $?
rfkill: invalid identifier: 2017
1
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/rfkill.c')
-rw-r--r-- | sys-utils/rfkill.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/sys-utils/rfkill.c b/sys-utils/rfkill.c index 2f744ecf6..08002b44f 100644 --- a/sys-utils/rfkill.c +++ b/sys-utils/rfkill.c @@ -244,8 +244,15 @@ static struct rfkill_id rfkill_id_to_type(const char *s) } } else if (isdigit(*s)) { /* assume a numeric character implies an index. */ + char filename[64]; + ret.index = strtou32_or_err(s, _("invalid identifier")); - ret.result = RFKILL_IS_INDEX; + snprintf(filename, sizeof(filename) - 1, + _PATH_SYS_RFKILL "/rfkill%" PRIu32 "/name", ret.index); + if (access(filename, F_OK) == 0) + ret.result = RFKILL_IS_INDEX; + else + ret.result = RFKILL_IS_INVALID; return ret; } |