[Midnightbsd-cvs] src [8892] trunk: add support for a exclamation char in regex in devd.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Mon Sep 26 18:31:48 EDT 2016
Revision: 8892
http://svnweb.midnightbsd.org/src/?rev=8892
Author: laffer1
Date: 2016-09-26 18:31:47 -0400 (Mon, 26 Sep 2016)
Log Message:
-----------
add support for a exclamation char in regex in devd.
Modified Paths:
--------------
trunk/etc/devd.conf
trunk/sbin/devd/devd.cc
trunk/sbin/devd/devd.conf.5
trunk/sbin/devd/devd.hh
Modified: trunk/etc/devd.conf
===================================================================
--- trunk/etc/devd.conf 2016-09-26 22:30:05 UTC (rev 8891)
+++ trunk/etc/devd.conf 2016-09-26 22:31:47 UTC (rev 8892)
@@ -38,6 +38,7 @@
#
notify 0 {
match "system" "IFNET";
+ match "subsystem" "!usbus[0-9]+";
match "type" "ATTACH";
action "/etc/pccard_ether $subsystem start";
};
Modified: trunk/sbin/devd/devd.cc
===================================================================
--- trunk/sbin/devd/devd.cc 2016-09-26 22:30:05 UTC (rev 8891)
+++ trunk/sbin/devd/devd.cc 2016-09-26 22:31:47 UTC (rev 8892)
@@ -251,7 +251,14 @@
match::match(config &c, const char *var, const char *re)
: _var(var), _re("^")
{
- _re.append(c.expand_string(string(re)));
+ if (!c.expand_string(string(re)).empty() &&
+ c.expand_string(string(re)).at(0) == '!') {
+ _re.append(c.expand_string(string(re)).substr(1));
+ _inv = 1;
+ } else {
+ _re.append(c.expand_string(string(re)));
+ _inv = 0;
+ }
_re.append("$");
regcomp(&_regex, _re.c_str(), REG_EXTENDED | REG_NOSUB | REG_ICASE);
}
@@ -268,10 +275,13 @@
bool retval;
if (Dflag)
- fprintf(stderr, "Testing %s=%s against %s\n", _var.c_str(),
- value.c_str(), _re.c_str());
+ fprintf(stderr, "Testing %s=%s against %s, invert=%d\n",
+ _var.c_str(), value.c_str(), _re.c_str(), _inv);
retval = (regexec(&_regex, value.c_str(), 0, NULL, 0) == 0);
+ if (_inv == 1)
+ retval = (retval == 0) ? 1 : 0;
+
return retval;
}
Modified: trunk/sbin/devd/devd.conf.5
===================================================================
--- trunk/sbin/devd/devd.conf.5 2016-09-26 22:30:05 UTC (rev 8891)
+++ trunk/sbin/devd/devd.conf.5 2016-09-26 22:31:47 UTC (rev 8892)
@@ -41,7 +41,7 @@
.\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
.\" SOFTWARE.
.\"
-.Dd March 8, 2009
+.Dd March 4, 2013
.Dt DEVD.CONF 5
.Os
.Sh NAME
@@ -121,6 +121,10 @@
.Ar regexp-name .
The variable is available throughout the rest of
the configuration file.
+If the string begins with
+.Ql \&! ,
+it matches if the regular expression formed by the rest of the string
+does not match.
All regular expressions have an implicit
.Ql ^$
around them.
Modified: trunk/sbin/devd/devd.hh
===================================================================
--- trunk/sbin/devd/devd.hh 2016-09-26 22:30:05 UTC (rev 8891)
+++ trunk/sbin/devd/devd.hh 2016-09-26 22:31:47 UTC (rev 8892)
@@ -92,6 +92,7 @@
private:
std::string _var;
std::string _re;
+ bool _inv;
regex_t _regex;
};
More information about the Midnightbsd-cvs
mailing list