}
}
+static bool cleanup_children(struct yaml_nl_node *parent)
+{
+ struct yaml_nl_node *child;
+
+ if (nl_list_empty(&parent->children)) {
+ struct ln_key_props *keys = parent->keys.lkl_list;
+ int i;
+
+ for (i = 1; i < parent->keys.lkl_maxattr; i++)
+ if (keys[i].lkp_value)
+ free(keys[i].lkp_value);
+ nl_list_del(&parent->list);
+ return true;
+ }
+
+ while ((child = get_next_child(parent, 0)) != NULL) {
+ if (cleanup_children(child))
+ free(child);
+ }
+
+ return false;
+}
+
/* This is the CB_VALID callback for the Netlink library that we
* have hooked into. Any successful Netlink message is passed to
* this function which handles both the incoming key tables and
scalar_attr_policy))
return NL_SKIP;
+ /* If root already exists this means we are updating the
+ * key table. Free old key table.
+ */
+ if (data->root && (nlh->nlmsg_flags & NLM_F_REPLACE)) {
+ cleanup_children(data->root);
+ free(data->root);
+ data->root = NULL;
+ }
+
if (attrs[LN_SCALAR_ATTR_LIST]) {
int rc = yaml_parse_key_list(data, NULL,
attrs[LN_SCALAR_ATTR_LIST]);
return NL_STOP;
}
-static bool cleanup_children(struct yaml_nl_node *parent)
-{
- struct yaml_nl_node *child;
-
- if (nl_list_empty(&parent->children)) {
- struct ln_key_props *keys = parent->keys.lkl_list;
- int i;
-
- for (i = 1; i < parent->keys.lkl_maxattr; i++)
- if (keys[i].lkp_value)
- free(keys[i].lkp_value);
- nl_list_del(&parent->list);
- return true;
- }
-
- while ((child = get_next_child(parent, 0)) != NULL) {
- if (cleanup_children(child))
- free(child);
- }
-
- return false;
-}
-
/* This is the libnl callback for when the last Netlink packet
* is finished being parsed or its called right away in case
* the Linux kernel reports back an error from the Netlink layer.