fix SIGINT handling
[project/ubus.git] / ubusd_obj.c
index 7fc7951..ffd5330 100644 (file)
@@ -98,7 +98,9 @@ struct ubus_object *ubusd_create_object_internal(struct ubus_object_type *type,
 
        obj->type = type;
        INIT_LIST_HEAD(&obj->list);
-       type->refcount++;
+       INIT_LIST_HEAD(&obj->events);
+       if (type)
+               type->refcount++;
 
        return obj;
 
@@ -117,11 +119,12 @@ struct ubus_object *ubusd_create_object(struct ubus_client *cl, struct blob_attr
        else if (attr[UBUS_ATTR_SIGNATURE])
                type = ubus_create_obj_type(attr[UBUS_ATTR_SIGNATURE]);
 
-       if (!type)
+       if (!!type ^ !!attr[UBUS_ATTR_OBJPATH])
                return NULL;
 
        obj = ubusd_create_object_internal(type, 0);
-       ubus_unref_object_type(type);
+       if (type)
+               ubus_unref_object_type(type);
 
        if (!obj)
                return NULL;
@@ -140,6 +143,7 @@ struct ubus_object *ubusd_create_object(struct ubus_client *cl, struct blob_attr
 
        obj->client = cl;
        list_add(&obj->list, &cl->objects);
+
        return obj;
 
 free:
@@ -149,6 +153,7 @@ free:
 
 void ubusd_free_object(struct ubus_object *obj)
 {
+       ubusd_event_cleanup_object(obj);
        if (obj->path.key) {
                avl_delete(&path, &obj->path);
                free(obj->path.key);
@@ -156,18 +161,15 @@ void ubusd_free_object(struct ubus_object *obj)
        if (!list_empty(&obj->list))
                list_del(&obj->list);
        ubus_free_id(&objects, &obj->id);
-       ubus_unref_object_type(obj->type);
+       if (obj->type)
+               ubus_unref_object_type(obj->type);
        free(obj);
 }
 
-static int ubus_cmp_path(const void *k1, const void *k2, void *ptr)
-{
-       return strcmp(k1, k2);
-}
-
 static void __init ubusd_obj_init(void)
 {
        ubus_init_id_tree(&objects);
        ubus_init_id_tree(&obj_types);
-       avl_init(&path, ubus_cmp_path, false, NULL);
+       ubus_init_string_tree(&path, false);
+       ubusd_event_init();
 }