pending->hdr.data = data;
memcpy(&pending->hdr.hdr, &buf->hdr, sizeof(buf->hdr));
memcpy(data, buf->data, blob_raw_len(buf->data));
- list_add(&pending->list, &ctx->pending);
+ list_add_tail(&pending->list, &ctx->pending);
if (ctx->sock.registered)
uloop_timeout_set(&ctx->pending_timer, 1);
}
break;
}
- ubus_process_obj_msg(ctx, buf);
+ ubus_process_obj_msg(ctx, buf, fd);
+ break;
+ case UBUS_MSG_MONITOR:
+ if (ctx->monitor_cb)
+ ctx->monitor_cb(ctx, buf->hdr.seq, buf->data);
break;
}
}
static void ubus_lookup_cb(struct ubus_request *ureq, int type, struct blob_attr *msg)
{
struct ubus_lookup_request *req;
- struct ubus_object_data obj;
+ struct ubus_object_data obj = {};
struct blob_attr **attr;
req = container_of(ureq, struct ubus_lookup_request, req);
!attr[UBUS_ATTR_OBJTYPE])
return;
- memset(&obj, 0, sizeof(obj));
obj.id = blob_get_u32(attr[UBUS_ATTR_OBJID]);
obj.path = blob_data(attr[UBUS_ATTR_OBJPATH]);
obj.type_id = blob_get_u32(attr[UBUS_ATTR_OBJTYPE]);
const char *pattern)
{
struct ubus_object *obj = &ev->obj;
- struct blob_buf b2;
+ struct blob_buf b2 = {};
int ret;
if (!obj->id) {
}
/* use a second buffer, ubus_invoke() overwrites the primary one */
- memset(&b2, 0, sizeof(b2));
blob_buf_init(&b2, 0);
blobmsg_add_u32(&b2, "object", obj->id);
if (pattern)
int ubus_connect_ctx(struct ubus_context *ctx, const char *path)
{
+ uloop_init();
memset(ctx, 0, sizeof(*ctx));
ctx->sock.fd = -1;
ctx->connection_lost = ubus_default_connection_lost;
ctx->pending_timer.cb = ubus_process_pending_msg;
- ctx->msgbuf.data = calloc(UBUS_MSG_CHUNK_SIZE, sizeof(char));
+ ctx->msgbuf.data = calloc(1, UBUS_MSG_CHUNK_SIZE);
if (!ctx->msgbuf.data)
return -1;
ctx->msgbuf_data_len = UBUS_MSG_CHUNK_SIZE;
avl_init(&ctx->objects, ubus_cmp_id, false, NULL);
if (ubus_reconnect(ctx, path)) {
free(ctx->msgbuf.data);
+ ctx->msgbuf.data = NULL;
return -1;
}
void ubus_shutdown(struct ubus_context *ctx)
{
blob_buf_free(&b);
+ if (!ctx)
+ return;
close(ctx->sock.fd);
+ uloop_timeout_cancel(&ctx->pending_timer);
free(ctx->msgbuf.data);
}