From: Darren Salt <linux@youmustbejoking.demon.co.uk>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org
Subject: [PATCH 6/6] Add filtering to "rfkill list".
Date: Fri, 22 Jan 2010 23:35:30 +0000 [thread overview]
Message-ID: <1264203330-20785-6-git-send-email-linux@youmustbejoking.demon.co.uk> (raw)
In-Reply-To: <1264203330-20785-5-git-send-email-linux@youmustbejoking.demon.co.uk>
---
rfkill.c | 34 +++++++++++++++++++++++++++++++---
1 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/rfkill.c b/rfkill.c
index 998728e..8fa4c6a 100644
--- a/rfkill.c
+++ b/rfkill.c
@@ -172,13 +172,25 @@ static struct rfkill_id rfkill_id_to_type(const char *s)
return ret;
}
-static int rfkill_list(void)
+static int rfkill_list(const char *param)
{
+ struct rfkill_id id = { .result = RFKILL_IS_INVALID };
struct rfkill_event event;
const char *name;
ssize_t len;
int fd;
+ if (param) {
+ id = rfkill_id_to_type(param);
+ if (id.result == RFKILL_IS_INVALID) {
+ fprintf(stderr, "Bogus %s argument '%s'.\n", "list", param);
+ return 2;
+ }
+ /* don't filter "all" */
+ if (id.result == RFKILL_IS_TYPE && id.type == RFKILL_TYPE_ALL)
+ id.result = RFKILL_IS_INVALID;
+ }
+
fd = open("/dev/rfkill", O_RDONLY);
if (fd < 0) {
perror("Can't open RFKILL control device");
@@ -208,6 +220,20 @@ static int rfkill_list(void)
if (event.op != RFKILL_OP_ADD)
continue;
+ /* filter out unwanted results */
+ switch (id.result)
+ {
+ case RFKILL_IS_TYPE:
+ if (event.type != id.type)
+ continue;
+ break;
+ case RFKILL_IS_INDEX:
+ if (event.idx != id.index)
+ continue;
+ break;
+ case RFKILL_IS_INVALID:; /* must be last */
+ }
+
name = get_name(event.idx);
printf("%u: %s: %s\n", event.idx, name,
@@ -271,7 +297,7 @@ static void usage(void)
fprintf(stderr, "Commands:\n");
fprintf(stderr, "\thelp\n");
fprintf(stderr, "\tevent\n");
- fprintf(stderr, "\tlist\n");
+ fprintf(stderr, "\tlist [IDENTIFIER]\n");
fprintf(stderr, "\tblock IDENTIFIER\n");
fprintf(stderr, "\tunblock IDENTIFIER\n");
fprintf(stderr, "where IDENTIFIER is the index no. of an rfkill switch or one of:\n");
@@ -304,7 +330,9 @@ int main(int argc, char **argv)
if (strcmp(*argv, "event") == 0) {
rfkill_event();
} else if (strcmp(*argv, "list") == 0) {
- rfkill_list();
+ argc--;
+ argv++;
+ rfkill_list(*argv); /* NULL is acceptable */
} else if (strcmp(*argv, "block") == 0 && argc > 1) {
argc--;
argv++;
--
1.6.5
next prev parent reply other threads:[~2010-01-22 23:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-22 23:35 [PATCH 1/6] Add "wlan" and "ultrawideband" as aliases for "wifi" and "uwb" Darren Salt
2010-01-22 23:35 ` [PATCH 2/6] Rearrange the help text for block & unblock Darren Salt
2010-01-22 23:35 ` [PATCH 3/6] Constification Darren Salt
2010-01-22 23:35 ` [PATCH 4/6] Return error codes instead of exiting Darren Salt
2010-01-22 23:35 ` [PATCH 5/6] Refactor rfkill index/type lookup: move it below rfkill_block Darren Salt
2010-01-22 23:35 ` Darren Salt [this message]
2010-01-23 12:52 ` [PATCH 1/6] Add "wlan" and "ultrawideband" as aliases for "wifi" and "uwb" Johannes Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1264203330-20785-6-git-send-email-linux@youmustbejoking.demon.co.uk \
--to=linux@youmustbejoking.demon.co.uk \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox