- 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
This commit is contained in:
Hiroki Sato 2011-10-26 02:11:28 +00:00
parent 5e6f40a264
commit 0321b694c7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=226775
4 changed files with 20 additions and 4 deletions

View File

@ -38,6 +38,7 @@ options {
# #
notify 0 { notify 0 {
match "system" "IFNET"; match "system" "IFNET";
match "subsystem" "!usbus[0-9]+";
match "type" "ATTACH"; match "type" "ATTACH";
action "/etc/pccard_ether $subsystem start"; action "/etc/pccard_ether $subsystem start";
}; };

View File

@ -251,7 +251,14 @@ match::match(config &c, const char *var, const char *re)
: _var(var) : _var(var)
{ {
_re = "^"; _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("$"); _re.append("$");
regcomp(&_regex, _re.c_str(), REG_EXTENDED | REG_NOSUB | REG_ICASE); regcomp(&_regex, _re.c_str(), REG_EXTENDED | REG_NOSUB | REG_ICASE);
} }
@ -268,10 +275,13 @@ match::do_match(config &c)
bool retval; bool retval;
if (Dflag) if (Dflag)
fprintf(stderr, "Testing %s=%s against %s\n", _var.c_str(), fprintf(stderr, "Testing %s=%s against %s, invert=%d\n",
value.c_str(), _re.c_str()); _var.c_str(), value.c_str(), _re.c_str(), _inv);
retval = (regexec(&_regex, value.c_str(), 0, NULL, 0) == 0); retval = (regexec(&_regex, value.c_str(), 0, NULL, 0) == 0);
if (_inv == 1)
retval = (retval == 0) ? 1 : 0;
return retval; return retval;
} }

View File

@ -41,7 +41,7 @@
.\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS .\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
.\" SOFTWARE. .\" SOFTWARE.
.\" .\"
.Dd March 8, 2009 .Dd October 25, 2011
.Dt DEVD.CONF 5 .Dt DEVD.CONF 5
.Os .Os
.Sh NAME .Sh NAME
@ -121,6 +121,10 @@ Creates a regular expression and assigns it to the variable
.Ar regexp-name . .Ar regexp-name .
The variable is available throughout the rest of The variable is available throughout the rest of
the configuration file. 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 All regular expressions have an implicit
.Ql ^$ .Ql ^$
around them. around them.

View File

@ -92,6 +92,7 @@ public:
private: private:
std::string _var; std::string _var;
std::string _re; std::string _re;
bool _inv;
regex_t _regex; regex_t _regex;
}; };