do not start instances with invalid config
[project/procd.git] / utils.c
diff --git a/utils.c b/utils.c
index cff67bd..88ed8c1 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -43,6 +43,20 @@ blobmsg_list_fill(struct blobmsg_list *list, void *data, int len)
 }
 
 void
+blobmsg_list_move(struct blobmsg_list *list, struct blobmsg_list *src)
+{
+       struct blobmsg_list_node *node, *tmp;
+       void *ptr;
+
+       avl_remove_all_elements(&src->avl, node, avl, tmp) {
+               if (!avl_insert(&list->avl, &node->avl)) {
+                       ptr = ((char *) node - list->node_offset);
+                       free(ptr);
+               }
+       }
+}
+
+void
 blobmsg_list_free(struct blobmsg_list *list)
 {
        struct blobmsg_list_node *node, *tmp;
@@ -53,3 +67,35 @@ blobmsg_list_free(struct blobmsg_list *list)
                free(ptr);
        }
 }
+
+bool
+blobmsg_list_equal(struct blobmsg_list *l1, struct blobmsg_list *l2)
+{
+       struct blobmsg_list_node *n1, *n2;
+       int count = l1->avl.count;
+
+       if (count != l2->avl.count)
+               return false;
+
+       n1 = avl_first_element(&l1->avl, n1, avl);
+       n2 = avl_first_element(&l2->avl, n2, avl);
+
+       while (count-- > 0) {
+               int len;
+
+               len = blob_len(n1->data);
+               if (len != blob_len(n2->data))
+                       return false;
+
+               if (memcmp(n1->data, n2->data, len) != 0)
+                       return false;
+
+               if (!count)
+                       break;
+
+               n1 = avl_next_element(n1, avl);
+               n2 = avl_next_element(n2, avl);
+       }
+
+       return true;
+}