- if (bnd->parent)
- PARA_INFO_LOG("added %s as child of %s\n", bnd->name, bnd->parent->name);
- else
- PARA_INFO_LOG("added %s as btr root\n", bnd->name);
+ if (!bnd->child) {
+ if (bnd->parent) {
+ list_add_tail(&btrn->node, &bnd->parent->children);
+ PARA_INFO_LOG("new leaf node: %s (child of %s)\n",
+ bnd->name, bnd->parent->name);
+ } else
+ PARA_INFO_LOG("added %s as btr root\n", bnd->name);
+ goto out;
+ }
+ if (!bnd->parent) {
+ assert(!bnd->child->parent);
+ PARA_INFO_LOG("new root: %s (was %s)\n",
+ bnd->name, bnd->child->name);
+ btrn->parent = NULL;
+ list_add_tail(&bnd->child->node, &btrn->children);
+ /* link it in */
+ bnd->child->parent = btrn;
+ goto out;
+ }
+ PARA_EMERG_LOG("inserting internal nodes not yet supported.\n");
+ exit(EXIT_FAILURE);
+ assert(bnd->child->parent == bnd->parent);
+out: