9 static int random_fd
= -1;
11 static int ubus_cmp_id(const void *k1
, const void *k2
, void *ptr
)
13 const uint32_t *id1
= k1
, *id2
= k2
;
21 static int ubus_cmp_str(const void *k1
, const void *k2
, void *ptr
)
23 return strcmp(k1
, k2
);
26 void ubus_init_string_tree(struct avl_tree
*tree
, bool dup
)
28 avl_init(tree
, ubus_cmp_str
, dup
, NULL
);
31 void ubus_init_id_tree(struct avl_tree
*tree
)
34 random_fd
= open("/dev/urandom", O_RDONLY
);
41 avl_init(tree
, ubus_cmp_id
, false, NULL
);
44 bool ubus_alloc_id(struct avl_tree
*tree
, struct ubus_id
*id
, uint32_t val
)
46 id
->avl
.key
= &id
->id
;
49 return avl_insert(tree
, &id
->avl
) == 0;
53 if (read(random_fd
, &id
->id
, sizeof(id
->id
)) != sizeof(id
->id
))
56 if (id
->id
< UBUS_SYSTEM_OBJECT_MAX
)
58 } while (avl_insert(tree
, &id
->avl
) != 0);