From patchwork Fri Jan 22 23:35:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darren Salt X-Patchwork-Id: 74808 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o0MNZglE018741 for ; Fri, 22 Jan 2010 23:35:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755229Ab0AVXfk (ORCPT ); Fri, 22 Jan 2010 18:35:40 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753953Ab0AVXfj (ORCPT ); Fri, 22 Jan 2010 18:35:39 -0500 Received: from lon1-post-3.mail.demon.net ([195.173.77.150]:53916 "EHLO lon1-post-3.mail.demon.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754262Ab0AVXfg (ORCPT ); Fri, 22 Jan 2010 18:35:36 -0500 Received: from youmustbejoking.demon.co.uk ([80.176.152.238] helo=pentagram.youmustbejoking.demon.co.uk) by lon1-post-3.mail.demon.net with esmtp (Exim 4.69) id 1NYT2N-0001JQ-dX; Fri, 22 Jan 2010 23:35:35 +0000 Received: from [192.168.0.5] (helo=localhost.localdomain) by pentagram.youmustbejoking.demon.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1NYT2M-0006FB-Tk; Fri, 22 Jan 2010 23:35:34 +0000 From: Darren Salt To: Johannes Berg Cc: linux-wireless@vger.kernel.org Subject: [PATCH 6/6] Add filtering to "rfkill list". Date: Fri, 22 Jan 2010 23:35:30 +0000 Message-Id: <1264203330-20785-6-git-send-email-linux@youmustbejoking.demon.co.uk> X-Mailer: git-send-email 1.6.5 In-Reply-To: <1264203330-20785-5-git-send-email-linux@youmustbejoking.demon.co.uk> References: <1264203330-20785-1-git-send-email-linux@youmustbejoking.demon.co.uk> <1264203330-20785-2-git-send-email-linux@youmustbejoking.demon.co.uk> <1264203330-20785-3-git-send-email-linux@youmustbejoking.demon.co.uk> <1264203330-20785-4-git-send-email-linux@youmustbejoking.demon.co.uk> <1264203330-20785-5-git-send-email-linux@youmustbejoking.demon.co.uk> X-SA-Exim-Connect-IP: 192.168.0.5 X-SA-Exim-Mail-From: linux@youmustbejoking.demon.co.uk X-SA-Exim-Scanned: No (on pentagram.youmustbejoking.demon.co.uk); SAEximRunCond expanded to false Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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++;