summaryrefslogtreecommitdiffstats
path: root/sbin/devd
diff options
context:
space:
mode:
authorhrs <hrs@FreeBSD.org>2011-10-26 02:11:28 +0000
committerhrs <hrs@FreeBSD.org>2011-10-26 02:11:28 +0000
commitfb5f47d254fc4d1fb1cd611706bdfab3515ff8e6 (patch)
tree4d011720f50d6e9301496fa296ee8c8ddd402c37 /sbin/devd
parentcfa150e0b1092907e533a6ee0ea1a9d21aa4f306 (diff)
downloadFreeBSD-src-fb5f47d254fc4d1fb1cd611706bdfab3515ff8e6.zip
FreeBSD-src-fb5f47d254fc4d1fb1cd611706bdfab3515ff8e6.tar.gz
- Add support for a "!" character in regex matching in devd(8). It inverts
the logic (true/false) of the matching. - Add "!usbus[0-9]+" to IFNET ATTACH notification handler in the default devd.conf to prevent rc.d/netif from running when usbus[0-9]+ is attached. Reviewed by: imp
Diffstat (limited to 'sbin/devd')
-rw-r--r--sbin/devd/devd.cc16
-rw-r--r--sbin/devd/devd.conf.56
-rw-r--r--sbin/devd/devd.hh1
3 files changed, 19 insertions, 4 deletions
diff --git a/sbin/devd/devd.cc b/sbin/devd/devd.cc
index 87d0580..fd3b6e3 100644
--- a/sbin/devd/devd.cc
+++ b/sbin/devd/devd.cc
@@ -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 @@ match::do_match(config &c)
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;
}
diff --git a/sbin/devd/devd.conf.5 b/sbin/devd/devd.conf.5
index e4dea72..09e902b 100644
--- a/sbin/devd/devd.conf.5
+++ b/sbin/devd/devd.conf.5
@@ -41,7 +41,7 @@
.\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
.\" SOFTWARE.
.\"
-.Dd March 8, 2009
+.Dd October 25, 2011
.Dt DEVD.CONF 5
.Os
.Sh NAME
@@ -121,6 +121,10 @@ Creates a regular expression and assigns it to the variable
.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.
diff --git a/sbin/devd/devd.hh b/sbin/devd/devd.hh
index b3c98f3..d70d178 100644
--- a/sbin/devd/devd.hh
+++ b/sbin/devd/devd.hh
@@ -92,6 +92,7 @@ public:
private:
std::string _var;
std::string _re;
+ bool _inv;
regex_t _regex;
};
OpenPOWER on IntegriCloud