Re: [PATCH 8/8] mdev: remember line number in rule

2019-12-17 Thread Lauri Kasanen
On Mon, 16 Dec 2019 22:56:56 +0100
Jan Klötzke  wrote:

> --- a/util-linux/mdev.c
> +++ b/util-linux/mdev.c
> @@ -299,6 +299,7 @@ struct rule {
>   IF_FEATURE_MDEV_EXEC(char *r_cmd;)
>   regex_t match;
>   struct envmatch *envmatch;
> + int lineno;
>  };

int16_t? Surely mdev.conf cannot be larger than 32767 lines.

- Lauri
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH 8/8] mdev: remember line number in rule

2019-12-16 Thread Jan Klötzke
When rules are caches from mdev.conf then their line number cannot be
retrieved from the parser anymore. Instead store the line number in the
rule so that a cached rule still shows the line number where it was
coming from.

Signed-off-by: Jan Klötzke 
---
 util-linux/mdev.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 81c4336af..9a8bea83f 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -299,6 +299,7 @@ struct rule {
IF_FEATURE_MDEV_EXEC(char *r_cmd;)
regex_t match;
struct envmatch *envmatch;
+   int lineno;
 };
 
 struct globals {
@@ -324,6 +325,7 @@ struct globals {
setup_common_bufsiz(); \
IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.maj = -1;) \
IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.mode = 0660;) \
+   IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.lineno = -1;) \
 } while (0)
 
 
@@ -340,6 +342,7 @@ static void make_default_cur_rule(void)
memset(&G.cur_rule, 0, sizeof(G.cur_rule));
G.cur_rule.maj = -1; /* "not a @major,minor rule" */
G.cur_rule.mode = 0660;
+   G.cur_rule.lineno = -1;
 }
 
 static void clean_up_cur_rule(void)
@@ -461,6 +464,7 @@ static void parse_next_rule(void)
IF_FEATURE_MDEV_EXEC(G.cur_rule.r_cmd = xstrdup(val);)
}
 
+   G.cur_rule.lineno = G.parser->lineno;
return;
  next_rule:
clean_up_cur_rule();
@@ -703,7 +707,10 @@ static void make_device(char *device_name, char *path, int 
operation)
}
/* else: it's final implicit "match-all" rule */
  rule_matches:
-   dbg2("rule matched, line %d", G.parser ? G.parser->lineno : -1);
+   if (rule->lineno >= 0)
+   dbg2("rule matched, line %d", rule->lineno);
+   else
+   dbg2s("no rule matched");
 #endif
/* Build alias name */
alias = NULL;
-- 
2.20.1

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox