From owner-freebsd-stable@FreeBSD.ORG Sun Jan 8 05:11:51 2006 Return-Path: X-Original-To: freebsd-stable@freebsd.org Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D5F4B16A41F; Sun, 8 Jan 2006 05:11:51 +0000 (GMT) (envelope-from gpalmer@freebsd.org) Received: from noop.colo.erols.net (noop.colo.erols.net [207.96.1.150]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6777C43D48; Sun, 8 Jan 2006 05:11:51 +0000 (GMT) (envelope-from gpalmer@freebsd.org) Received: from uucp by noop.colo.erols.net with local-rmail (Exim 4.52 (FreeBSD)) id 1EvSqM-000DAp-P2; Sun, 08 Jan 2006 00:11:50 -0500 Received: from localhost.home.in-addr.com ([127.0.0.1]:56831) by rimmer.home.in-addr.com with esmtp (Exim 4.60 (FreeBSD)) (envelope-from ) id 1EvSq8-000DRb-Oi; Sun, 08 Jan 2006 05:11:36 +0000 Message-ID: <43C09F08.1080707@freebsd.org> Date: Sun, 08 Jan 2006 05:11:36 +0000 From: Gary Palmer User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.12) Gecko/20051130 X-Accept-Language: en-gb, en, en-us MIME-Version: 1.0 To: Sam Leffler References: <43C05270.60106@freebsd.org> <43C07B16.7050505@errno.com> In-Reply-To: <43C07B16.7050505@errno.com> Content-Type: multipart/mixed; boundary="------------060007040507070002080403" Cc: freebsd-stable@freebsd.org Subject: Re: devd and caseful device ID matching on 6.0 X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Jan 2006 05:11:52 -0000 This is a multi-part message in MIME format. --------------060007040507070002080403 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sam Leffler wrote: > At one point I added shorthand logic in devd for things like vendor, > device, subvendor, etc. that did numeric comparisons instead of > regex's. It might be worthwhile to extend the grammar to have a > numeric match operator. Something like the attached patch? It seems to work in my test case, although I'm pretty sure its not as defensive as it could be against bad inputs. (note: The patch is against 6.0-STABLE, not head) Thanks, Gary --------------060007040507070002080403 Content-Type: text/plain; name="devd-patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="devd-patch" Index: devd.cc =================================================================== RCS file: /home/ncvs/src/sbin/devd/devd.cc,v retrieving revision 1.22.2.5 diff -u -r1.22.2.5 devd.cc --- devd.cc 19 Dec 2005 03:33:05 -0000 1.22.2.5 +++ devd.cc 8 Jan 2006 05:09:30 -0000 @@ -192,6 +192,25 @@ return retval; } +equals::equals(config &c, const char *var, const char *val) + : _var(var) +{ + _val = strtol(val, NULL, 0); +} + +bool +equals::do_match(config &c) +{ + string value = c.get_variable(_var); + long val = strtol(value.c_str(), NULL, 0); + + if (Dflag) + fprintf(stderr, "Testing %s=%s (0x%x) against 0x%x\n", + _var.c_str(), value.c_str(), val, _val); + + return(val == _val); +} + #include #include #include @@ -850,6 +869,15 @@ } eps * +new_equals(const char *var, const char *val) +{ + eps *e = new equals(cfg, var, val); + free(const_cast(var)); + free(const_cast(val)); + return (e); +} + +eps * new_media(const char *var, const char *re) { eps *e = new media(cfg, var, re); Index: devd.h =================================================================== RCS file: /home/ncvs/src/sbin/devd/devd.h,v retrieving revision 1.5 diff -u -r1.5 devd.h --- devd.h 10 Jul 2005 03:37:15 -0000 1.5 +++ devd.h 8 Jan 2006 05:07:09 -0000 @@ -43,6 +43,7 @@ void add_notify(int, struct event_proc *); struct event_proc *add_to_event_proc(struct event_proc *, struct eps *); struct eps *new_match(const char *, const char *); +struct eps *new_equals(const char *, const char *); struct eps *new_media(const char *, const char *); struct eps *new_action(const char *); void set_pidfile(const char *); Index: devd.hh =================================================================== RCS file: /home/ncvs/src/sbin/devd/devd.hh,v retrieving revision 1.3 diff -u -r1.3 devd.hh --- devd.hh 10 Jul 2005 03:37:15 -0000 1.3 +++ devd.hh 8 Jan 2006 05:07:09 -0000 @@ -96,6 +96,21 @@ }; /** + * equal is the subclass used to match an individual variable using + * numeric comparitors instead of a regex. Its actions are nops. + */ +class equals : public eps +{ +public: + equals(config &, const char *var, const char *val); + virtual bool do_match(config &); + virtual bool do_action(config &) { return true; } +private: + std::string _var; + long _val; +}; + +/** * media is the subclass used to match an individual variable. Its * actions are nops. */ Index: parse.y =================================================================== RCS file: /home/ncvs/src/sbin/devd/parse.y,v retrieving revision 1.5 diff -u -r1.5 parse.y --- parse.y 10 Jul 2005 03:37:15 -0000 1.5 +++ parse.y 8 Jan 2006 05:07:09 -0000 @@ -48,6 +48,7 @@ %token ID %token OPTIONS SET DIRECTORY PID_FILE DEVICE_NAME ACTION MATCH %token ATTACH DETACH NOMATCH NOTIFY MEDIA_TYPE CLASS SUBDEVICE +%token EQUALS %type match_or_action_list %type match_or_action match action @@ -135,6 +136,7 @@ match : MATCH STRING STRING SEMICOLON { $$ = new_match($2, $3); } + | EQUALS STRING STRING SEMICOLON { $$ = new_equals($2, $3); } | DEVICE_NAME STRING SEMICOLON { $$ = new_match(strdup("device-name"), $2); } | MEDIA_TYPE STRING SEMICOLON Index: token.l =================================================================== RCS file: /home/ncvs/src/sbin/devd/token.l,v retrieving revision 1.6 diff -u -r1.6 token.l --- token.l 10 Jul 2005 03:37:15 -0000 1.6 +++ token.l 8 Jan 2006 05:07:09 -0000 @@ -95,6 +95,7 @@ subdevice { return SUBDEVICE; } action { return ACTION; } match { return MATCH; } +equals { return EQUALS; } nomatch { return NOMATCH; } notify { return NOTIFY; } [A-Za-z][A-Za-z0-9_-]* { --------------060007040507070002080403--