ubusd: fix issue caused by an implicit cast
[project/ubus.git] / ubusd_proto.c
index b591384..72da7a7 100644 (file)
@@ -80,11 +80,15 @@ void
 ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub,
                        uint8_t type)
 {
+       /* keep the fd to be passed if it is UBUS_MSG_INVOKE */
+       int fd = ub->fd;
        ub = ubus_reply_from_blob(ub, true);
        if (!ub)
                return;
 
        ub->hdr.type = type;
+       ub->fd = fd;
+
        ubus_msg_send(cl, ub, true);
 }
 
@@ -156,7 +160,7 @@ static int ubusd_handle_add_object(struct ubus_client *cl, struct ubus_msg_buf *
 static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, struct ubus_object *obj)
 {
        struct ubus_method *m;
-       int cnt = 0;
+       int all_cnt = 0, cnt = 0;
        void *s;
 
        if (!obj->type)
@@ -170,6 +174,7 @@ static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, stru
 
        s = blob_nest_start(&b, UBUS_ATTR_SIGNATURE);
        list_for_each_entry(m, &obj->type->methods, list) {
+               all_cnt++;
                if (!ubusd_acl_check(cl, obj->path.key, blobmsg_name(m->data), UBUS_ACL_ACCESS)) {
                        blobmsg_add_blob(&b, m->data);
                        cnt++;
@@ -177,7 +182,7 @@ static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, stru
        }
        blob_nest_end(&b, s);
 
-       if (cnt)
+       if (cnt || !all_cnt)
                ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA);
 }
 
@@ -446,7 +451,7 @@ void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub
        if (ub->hdr.type < __UBUS_MSG_LAST)
                cb = handlers[ub->hdr.type];
 
-       if (ub->hdr.type != UBUS_MSG_STATUS)
+       if (ub->hdr.type != UBUS_MSG_STATUS && ub->hdr.type != UBUS_MSG_INVOKE)
                ubus_msg_close_fd(ub);
 
        if (cb)