mirror of
https://github.com/SELinuxProject/selinux
synced 2025-02-19 02:56:49 +00:00
libsepol/cil: Add cil_tree_node_remove function
Add the function cil_tree_node_remove() which takes a node pointer as an input, finds the parent, walks the list of nodes to the node prior to the given node, updates that node's next pointer to remove the given node from the tree, and then destroys the node. Signed-off-by: James Carter <jwcart2@gmail.com> Reviewed-by: Daniel Burgener <dburgener@linux.microsoft.com> Acked-by: Petr Lautrbach <lautrbach@redhat.com>
This commit is contained in:
parent
085e330062
commit
9d5ca92be1
@ -248,6 +248,41 @@ void cil_tree_node_destroy(struct cil_tree_node **node)
|
||||
*node = NULL;
|
||||
}
|
||||
|
||||
void cil_tree_node_remove(struct cil_tree_node *node)
|
||||
{
|
||||
struct cil_tree_node *parent, *curr;
|
||||
|
||||
if (node == NULL || node->parent == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent = node->parent;
|
||||
|
||||
if (parent->cl_head == node) {
|
||||
if (parent->cl_tail == node) {
|
||||
parent->cl_tail = NULL;
|
||||
}
|
||||
parent->cl_head = node->next;
|
||||
cil_tree_node_destroy(&node);
|
||||
return;
|
||||
}
|
||||
|
||||
curr = parent->cl_head;
|
||||
while (curr && curr->next != node) {
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
if (curr == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (parent->cl_tail == node) {
|
||||
parent->cl_tail = curr;
|
||||
}
|
||||
curr->next = node->next;
|
||||
cil_tree_node_destroy(&node);
|
||||
}
|
||||
|
||||
/* Perform depth-first walk of the tree
|
||||
Parameters:
|
||||
start_node: root node to start walking from
|
||||
|
@ -63,6 +63,7 @@ void cil_tree_children_destroy(struct cil_tree_node *node);
|
||||
|
||||
void cil_tree_node_init(struct cil_tree_node **node);
|
||||
void cil_tree_node_destroy(struct cil_tree_node **node);
|
||||
void cil_tree_node_remove(struct cil_tree_node *node);
|
||||
|
||||
//finished values
|
||||
#define CIL_TREE_SKIP_NOTHING 0
|
||||
|
Loading…
Reference in New Issue
Block a user