ubus/lua: pass notification name to callback
[project/ubus.git] / libubus-obj.c
index a9972c5..c1931b3 100644 (file)
@@ -31,7 +31,8 @@ ubus_process_unsubscribe(struct ubus_context *ctx, struct ubus_msghdr *hdr,
        if (s->remove_cb)
                s->remove_cb(ctx, s, blob_get_u32(attrbuf[UBUS_ATTR_TARGET]));
 
-       close(fd);
+       if (fd >= 0)
+               close(fd);
 }
 
 static void
@@ -45,7 +46,8 @@ ubus_process_notify(struct ubus_context *ctx, struct ubus_msghdr *hdr,
        if (obj->subscribe_cb)
                obj->subscribe_cb(ctx, obj);
 
-       close(fd);
+       if (fd >= 0)
+               close(fd);
 }
 static void
 ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr,
@@ -95,7 +97,8 @@ found:
        ret = obj->methods[method].handler(ctx, obj, &req,
                                           blob_data(attrbuf[UBUS_ATTR_METHOD]),
                                           attrbuf[UBUS_ATTR_DATA]);
-       close(req.req_fd);
+       if (req.req_fd >= 0)
+               close(req.req_fd);
        if (req.deferred || no_reply)
                return;
 
@@ -237,12 +240,12 @@ static void ubus_remove_object_cb(struct ubus_request *req, int type, struct blo
        if (!attrbuf[UBUS_ATTR_OBJID])
                return;
 
+       avl_delete(&req->ctx->objects, &obj->avl);
+
        obj->id = 0;
 
        if (attrbuf[UBUS_ATTR_OBJTYPE] && obj->type)
                obj->type->id = 0;
-
-       avl_delete(&req->ctx->objects, &obj->avl);
 }
 
 int ubus_remove_object(struct ubus_context *ctx, struct ubus_object *obj)