summaryrefslogtreecommitdiffstats
path: root/sys-utils/rfkill.c
diff options
context:
space:
mode:
authorSami Kerola2017-06-25 02:04:41 +0200
committerSami Kerola2017-08-30 21:32:48 +0200
commitb03378e793c75e3a6a2d939328c0262b69088b03 (patch)
tree2c56322567dd1f08ee5e3852dfc51fb84bfe767f /sys-utils/rfkill.c
parentrfkill: update manual page (diff)
downloadkernel-qcow2-util-linux-b03378e793c75e3a6a2d939328c0262b69088b03.tar.gz
kernel-qcow2-util-linux-b03378e793c75e3a6a2d939328c0262b69088b03.tar.xz
kernel-qcow2-util-linux-b03378e793c75e3a6a2d939328c0262b69088b03.zip
rfkill: clarify 'all devices' handling
Stop using RFKILL_IS_INVALID a marker when rfkill is iterating over all devices. Addition of RFKIL_IS_ALL should make this a lot easier to digest, especially if reading code in hurry. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/rfkill.c')
-rw-r--r--sys-utils/rfkill.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/sys-utils/rfkill.c b/sys-utils/rfkill.c
index 6212128f5..e0671ffec 100644
--- a/sys-utils/rfkill.c
+++ b/sys-utils/rfkill.c
@@ -60,6 +60,7 @@ struct rfkill_id {
RFKILL_IS_INVALID,
RFKILL_IS_TYPE,
RFKILL_IS_INDEX,
+ RFKILL_IS_ALL
} result;
};
@@ -180,7 +181,10 @@ static struct rfkill_id rfkill_id_to_type(const char *s)
for (p = rfkill_type_strings; p->name != NULL; p++) {
if (!strcmp(s, p->name)) {
ret.type = p->type;
- ret.result = RFKILL_IS_TYPE;
+ if (!strcmp(s, "all"))
+ ret.result = RFKILL_IS_ALL;
+ else
+ ret.result = RFKILL_IS_TYPE;
return ret;
}
}
@@ -197,7 +201,7 @@ static struct rfkill_id rfkill_id_to_type(const char *s)
static int rfkill_list(const char *param)
{
- struct rfkill_id id = { .result = RFKILL_IS_INVALID };
+ struct rfkill_id id = { .result = RFKILL_IS_ALL };
struct rfkill_event event;
const char *name;
ssize_t len;
@@ -209,9 +213,6 @@ static int rfkill_list(const char *param)
warnx(_("invalid identifier: %s"), param);
return 1;
}
- /* don't filter "all" */
- if (id.result == RFKILL_IS_TYPE && id.type == RFKILL_TYPE_ALL)
- id.result = RFKILL_IS_INVALID;
}
fd = open(_PATH_DEV_RFKILL, O_RDONLY);
@@ -253,7 +254,7 @@ static int rfkill_list(const char *param)
if (event.idx != id.index)
continue;
break;
- case RFKILL_IS_INVALID:
+ case RFKILL_IS_ALL:
break;
default:
abort();
@@ -273,38 +274,38 @@ static int rfkill_list(const char *param)
static int rfkill_block(uint8_t block, const char *param)
{
struct rfkill_id id;
- struct rfkill_event event;
+ struct rfkill_event event = {
+ .op = RFKILL_OP_CHANGE_ALL,
+ .soft = block,
+ 0
+ };
ssize_t len;
int fd;
id = rfkill_id_to_type(param);
- if (id.result == RFKILL_IS_INVALID) {
- warnx(_("invalid identifier: %s"), param);
- return 1;
- }
-
- fd = open(_PATH_DEV_RFKILL, O_RDWR);
- if (fd < 0) {
- warn(_("cannot open %s"), _PATH_DEV_RFKILL);
- return 1;
- }
- memset(&event, 0, sizeof(event));
switch (id.result) {
+ case RFKILL_IS_INVALID:
+ warnx(_("invalid identifier: %s"), param);
+ return 1;
case RFKILL_IS_TYPE:
- event.op = RFKILL_OP_CHANGE_ALL;
event.type = id.type;
break;
case RFKILL_IS_INDEX:
event.op = RFKILL_OP_CHANGE;
event.idx = id.index;
break;
- case RFKILL_IS_INVALID:
+ case RFKILL_IS_ALL:
break;
default:
abort();
}
- event.soft = block;
+
+ fd = open(_PATH_DEV_RFKILL, O_RDWR);
+ if (fd < 0) {
+ warn(_("cannot open %s"), _PATH_DEV_RFKILL);
+ return 1;
+ }
len = write(fd, &event, sizeof(event));
if (len < 0)