- }
-
- /* This line matches: stop parsing the file after parsing
- * the rest of fields unless keep_matching == 1 */
-
- /* 2nd field: uid:gid - device ownership */
- parse_chown_usergroup_or_die(&ugid, tokens[1]);
-
- /* 3rd field: mode - device permissions */
- mode = strtoul(tokens[2], NULL, 8);
-
- val = tokens[3];
- /* 4th field (opt): >|=alias */
-# if ENABLE_FEATURE_MDEV_RENAME
- if (!val)
- goto line_matches;
- aliaslink = val[0];
- if (aliaslink == '>' || aliaslink == '=') {
- char *a, *s, *st;
-# if ENABLE_FEATURE_MDEV_RENAME_REGEXP
- char *p;
- unsigned i, n;
-# endif
- a = val;
- s = strchrnul(val, ' ');
- st = strchrnul(val, '\t');
- if (st < s)
- s = st;
- val = (s[0] && s[1]) ? s+1 : NULL;
- s[0] = '\0';
-
-# if ENABLE_FEATURE_MDEV_RENAME_REGEXP
- /* substitute %1..9 with off[1..9], if any */
- n = 0;
- s = a;
- while (*s)
- if (*s++ == '%')
- n++;
-
- p = alias = xzalloc(strlen(a) + n * strlen(name));
- s = a + 1;
- while (*s) {
- *p = *s;
- if ('%' == *s) {
- i = (s[1] - '0');
- if (i <= 9 && off[i].rm_so >= 0) {
- n = off[i].rm_eo - off[i].rm_so;
- strncpy(p, name + off[i].rm_so, n);
- p += n - 1;
- s++;
+ /* else: regex to match [subsystem/]device_name */
+
+ {
+ regex_t match;
+ int result;
+
+ xregcomp(&match, val, REG_EXTENDED);
+ result = regexec(&match, str_to_match, ARRAY_SIZE(off), off, 0);
+ regfree(&match);
+ //bb_error_msg("matches:");
+ //for (int i = 0; i < ARRAY_SIZE(off); i++) {
+ // if (off[i].rm_so < 0) continue;
+ // bb_error_msg("match %d: '%.*s'\n", i,
+ // (int)(off[i].rm_eo - off[i].rm_so),
+ // device_name + off[i].rm_so);
+ //}
+
+ /* If no match, skip rest of line */
+ /* (regexec returns whole pattern as "range" 0) */
+ if (result || off[0].rm_so
+ || ((int)off[0].rm_eo != (int)strlen(str_to_match))
+ ) {
+ continue; /* this line doesn't match */
+ }
+ }
+ line_matches:
+ /* This line matches. Stop parsing after parsing
+ * the rest the line unless keep_matching == 1 */
+
+ /* 2nd field: uid:gid - device ownership */
+ if (get_uidgid(&ugid, tokens[1], 1) == 0)
+ bb_error_msg("unknown user/group %s on line %d", tokens[1], parser->lineno);
+
+ /* 3rd field: mode - device permissions */
+ /* mode = strtoul(tokens[2], NULL, 8); */
+ bb_parse_mode(tokens[2], &mode);
+
+ val = tokens[3];
+ /* 4th field (opt): >|=alias */
+
+ if (ENABLE_FEATURE_MDEV_RENAME && val) {
+ aliaslink = val[0];
+ if (aliaslink == '>' || aliaslink == '=') {
+ char *a, *s, *st;
+ char *p;
+ unsigned i, n;
+
+ a = val;
+ s = strchrnul(val, ' ');
+ st = strchrnul(val, '\t');
+ if (st < s)
+ s = st;
+ val = (s[0] && s[1]) ? s+1 : NULL;
+ s[0] = '\0';
+
+ if (ENABLE_FEATURE_MDEV_RENAME_REGEXP) {
+ /* substitute %1..9 with off[1..9], if any */
+ n = 0;
+ s = a;
+ while (*s)
+ if (*s++ == '%')
+ n++;
+
+ p = alias = xzalloc(strlen(a) + n * strlen(str_to_match));
+ s = a + 1;
+ while (*s) {
+ *p = *s;
+ if ('%' == *s) {
+ i = (s[1] - '0');
+ if (i <= 9 && off[i].rm_so >= 0) {
+ n = off[i].rm_eo - off[i].rm_so;
+ strncpy(p, str_to_match + off[i].rm_so, n);
+ p += n - 1;
+ s++;
+ }
+ }
+ p++;
+ s++;
+ }
+ } else {
+ alias = xstrdup(a + 1);