From 509881dc2004a449e1da378ca22b164546a50d32 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 31 Dec 2009 04:33:58 +0100 Subject: [PATCH] buffer tree: Fix btr_splice_out_node(). --- buffer_tree.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/buffer_tree.c b/buffer_tree.c index 28999df5..1bc95298 100644 --- a/buffer_tree.c +++ b/buffer_tree.c @@ -41,6 +41,8 @@ struct btr_node { #define FOR_EACH_CHILD(_tn, _btrn) list_for_each_entry((_tn), \ &((_btrn)->children), node) +#define FOR_EACH_CHILD_SAFE(_tn, _tmp, _btrn) \ + list_for_each_entry_safe((_tn), (_tmp), &((_btrn)->children), node) #define FOR_EACH_BUFFER_REF(_br, _btrn) \ list_for_each_entry((_br), &(_btrn)->input_queue, node) @@ -60,6 +62,10 @@ struct btr_node *btr_new_node(const char *name, struct btr_node *parent, list_add_tail(&btrn->node, &parent->children); INIT_LIST_HEAD(&btrn->children); INIT_LIST_HEAD(&btrn->input_queue); + if (parent) + PARA_INFO_LOG("added %s as child of %s\n", name, parent->name); + else + PARA_INFO_LOG("added %s as btr root\n", name); return btrn; } @@ -221,7 +227,7 @@ size_t btr_get_input_queue_size(struct btr_node *btrn) int btr_splice_out_node(struct btr_node *btrn) { - struct btr_node *ch; + struct btr_node *ch, *tmp; if (!btrn) return -ERRNO_TO_PARA_ERROR(EINVAL); @@ -230,8 +236,14 @@ int btr_splice_out_node(struct btr_node *btrn) PARA_NOTICE_LOG("splicing out %s\n", btrn->name); if (btrn->parent) list_del(&btrn->node); - FOR_EACH_CHILD(ch, btrn) + FOR_EACH_CHILD_SAFE(ch, tmp, btrn) { + PARA_INFO_LOG("parent(%s): %s\n", ch->name, + btrn->parent? btrn->parent->name : "NULL"); ch->parent = btrn->parent; + if (btrn->parent) + list_move(&ch->node, &btrn->parent->children); + } + assert(list_empty(&btrn->children)); free(btrn->name); free(btrn); return 1; @@ -269,16 +281,20 @@ int btr_exec_up(struct btr_node *btrn, const char *command, char **value_result) for (; btrn; btrn = btrn->parent) { struct btr_node *parent = btrn->parent; - PARA_CRIT_LOG("parent: %p\n", parent); if (!parent) return -ERRNO_TO_PARA_ERROR(ENOTSUP); if (!parent->execute) continue; + PARA_INFO_LOG("parent: %s, cmd: %s\n", parent->name, command); ret = parent->execute(parent, command, value_result); if (ret == -ERRNO_TO_PARA_ERROR(ENOTSUP)) continue; if (ret < 0) return ret; + if (value_result && *value_result) + PARA_NOTICE_LOG("%s(%s): %s\n", command, parent->name, + *value_result); + return 1; } return -ERRNO_TO_PARA_ERROR(ENOTSUP); } -- 2.39.5