konfd can not handle multiple unset of non-unique pattern correctly

Skip to first unread message

zyxwvu S

Dec 3, 2020, 3:47:38 AM12/3/20
to klish-dev
I have multiple config items in konfd:

ip route-static
ip route-static
ip route-static
ip route-static

I want to clear them with a single `konf -- -un -r "^ip route-static "` but each time I run konf, only the first item will be removed.

I fount that, in bin/konfd.c, code handling KONF_QUERY_OP_UNSET is calling `konf_tree_del_pattern` with BOOL_TRUE as the parameter `uniq` and ignoring the `-n`
 option which can be retrieved with `konf_query__get_unique(query)`. Is this delibrate? If I map it to the '-n' parameter, will I break anything?

zyxwvu S

Dec 3, 2020, 4:09:43 AM12/3/20
to klish-dev
After some investigation, I found it's not a matter of `uniq`. I have made this patch that will fix this.

From 64579c0109dfbd5844d8e645e3e1b7d2daaf7718 Mon Sep 17 00:00:00 2001
From: zyxwvu Shi <i...@shiyc.cn>
Date: Thu, 3 Dec 2020 17:05:20 +0800
Subject: [PATCH] Fix multiple config item removal.

`lub_list_del` resets iter->next to NULL, and the later copied tmp->next
is also reset to NULL. This terminates the configuration iteration loop
and prevents all matching configuration from being deleted.

Signed-off-by: zyxwvu Shi <i...@shiyc.cn>
 konf/tree/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/konf/tree/tree.c b/konf/tree/tree.c
index db2fdff..7d9c787 100644
--- a/konf/tree/tree.c
+++ b/konf/tree/tree.c
@@ -272,9 +272,9 @@ int konf_tree_del_pattern(konf_tree_t *this,
+               lub_list_node_copy(tmp, iter);
                lub_list_del(this->list, iter);
-               lub_list_node_copy(tmp, iter);
                iter = tmp;
2.24.3 (Apple Git-128)

Serj Kalichev

Dec 8, 2020, 11:25:53 AM12/8/20
to klis...@googlegroups.com
Thanks! Applied

03.12.2020 12:09, zyxwvu S пишет:
You received this message because you are subscribed to the Google Groups "klish-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to klish-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/klish-dev/607973f5-c99f-4065-b19e-16f2030abc20n%40googlegroups.com.

Reply all
Reply to author
0 new messages