projects
/
project
/
ubus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
libubus: add socket EOF handling to ubus_complete_request()
[project/ubus.git]
/
libubus-req.c
diff --git
a/libubus-req.c
b/libubus-req.c
index
8475dc9
..
416adab
100644
(file)
--- a/
libubus-req.c
+++ b/
libubus-req.c
@@
-153,12
+153,17
@@
int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req,
timeout = time_end - get_time_msec();
if (timeout <= 0) {
ubus_set_req_status(req, UBUS_STATUS_TIMEOUT);
timeout = time_end - get_time_msec();
if (timeout <= 0) {
ubus_set_req_status(req, UBUS_STATUS_TIMEOUT);
+ uloop_cancelled = cancelled;
break;
}
}
ubus_poll_data(ctx, (unsigned int) timeout);
uloop_cancelled = cancelled;
break;
}
}
ubus_poll_data(ctx, (unsigned int) timeout);
uloop_cancelled = cancelled;
+ if (ctx->sock.eof) {
+ ubus_set_req_status(req, UBUS_STATUS_CONNECTION_FAILED);
+ break;
+ }
}
ctx->stack_depth--;
if (ctx->stack_depth)
}
ctx->stack_depth--;
if (ctx->stack_depth)
@@
-174,7
+179,7
@@
int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req,
if (!registered) {
uloop_fd_delete(&ctx->sock);
if (!registered) {
uloop_fd_delete(&ctx->sock);
- if (ctx->stack_depth)
+ if (
!
ctx->stack_depth)
ctx->pending_timer.cb(&ctx->pending_timer);
}
ctx->pending_timer.cb(&ctx->pending_timer);
}
@@
-301,9
+306,9
@@
int ubus_notify(struct ubus_context *ctx, struct ubus_object *obj,
return ubus_complete_request(ctx, &req.req, timeout);
}
return ubus_complete_request(ctx, &req.req, timeout);
}
-static bool ubus_get_status(struct ubus_msghdr
*hdr
, int *ret)
+static bool ubus_get_status(struct ubus_msghdr
_buf *buf
, int *ret)
{
{
- struct blob_attr **attrbuf = ubus_parse_msg(
ubus_msghdr_data(hdr)
);
+ struct blob_attr **attrbuf = ubus_parse_msg(
buf->data
);
if (!attrbuf[UBUS_ATTR_STATUS])
return false;
if (!attrbuf[UBUS_ATTR_STATUS])
return false;
@@
-313,27
+318,26
@@
static bool ubus_get_status(struct ubus_msghdr *hdr, int *ret)
}
static int
}
static int
-ubus_process_req_status(struct ubus_request *req, struct ubus_msghdr
*hdr
)
+ubus_process_req_status(struct ubus_request *req, struct ubus_msghdr
_buf *buf
)
{
int ret = UBUS_STATUS_INVALID_ARGUMENT;
{
int ret = UBUS_STATUS_INVALID_ARGUMENT;
- ubus_get_status(
hdr
, &ret);
- req->peer =
hdr->
peer;
+ ubus_get_status(
buf
, &ret);
+ req->peer =
buf->hdr.
peer;
ubus_set_req_status(req, ret);
return ret;
}
static void
ubus_set_req_status(req, ret);
return ret;
}
static void
-ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr
*hdr
)
+ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr
_buf *buf
)
{
{
- struct blob_attr *msg_data = ubus_msghdr_data(hdr);
struct ubus_pending_data *data;
int len;
if (!req->blocked) {
req->blocked = true;
struct ubus_pending_data *data;
int len;
if (!req->blocked) {
req->blocked = true;
- req_data_cb(req,
hdr->type, msg_
data);
+ req_data_cb(req,
buf->hdr.type, buf->
data);
__ubus_process_req_data(req);
req->blocked = false;
__ubus_process_req_data(req);
req->blocked = false;
@@
-343,13
+347,13
@@
ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr *hdr)
return;
}
return;
}
- len = blob_raw_len(
msg_
data);
+ len = blob_raw_len(
buf->
data);
data = calloc(1, sizeof(*data) + len);
if (!data)
return;
data = calloc(1, sizeof(*data) + len);
if (!data)
return;
- data->type =
hdr->
type;
- memcpy(data->data,
msg_
data, len);
+ data->type =
buf->hdr.
type;
+ memcpy(data->data,
buf->
data, len);
list_add(&data->list, &req->pending);
}
list_add(&data->list, &req->pending);
}
@@
-397,7
+401,7
@@
ubus_find_request(struct ubus_context *ctx, uint32_t seq, uint32_t peer, int *id
return NULL;
}
return NULL;
}
-static void ubus_process_notify_status(struct ubus_request *req, int id, struct ubus_msghdr
*hdr
)
+static void ubus_process_notify_status(struct ubus_request *req, int id, struct ubus_msghdr
_buf *buf
)
{
struct ubus_notify_request *nreq;
struct blob_attr **tb;
{
struct ubus_notify_request *nreq;
struct blob_attr **tb;
@@
-410,7
+414,7
@@
static void ubus_process_notify_status(struct ubus_request *req, int id, struct
if (!id) {
/* first id: ubusd's status message with a list of ids */
if (!id) {
/* first id: ubusd's status message with a list of ids */
- tb = ubus_parse_msg(
ubus_msghdr_data(hdr)
);
+ tb = ubus_parse_msg(
buf->data
);
if (tb[UBUS_ATTR_SUBSCRIBERS]) {
blob_for_each_attr(cur, tb[UBUS_ATTR_SUBSCRIBERS], rem) {
if (!blob_check_type(blob_data(cur), blob_len(cur), BLOB_ATTR_INT32))
if (tb[UBUS_ATTR_SUBSCRIBERS]) {
blob_for_each_attr(cur, tb[UBUS_ATTR_SUBSCRIBERS], rem) {
if (!blob_check_type(blob_data(cur), blob_len(cur), BLOB_ATTR_INT32))
@@
-425,7
+429,7
@@
static void ubus_process_notify_status(struct ubus_request *req, int id, struct
}
}
} else {
}
}
} else {
- ubus_get_status(
hdr
, &ret);
+ ubus_get_status(
buf
, &ret);
if (nreq->status_cb)
nreq->status_cb(nreq, id, ret);
}
if (nreq->status_cb)
nreq->status_cb(nreq, id, ret);
}
@@
-434,8
+438,9
@@
static void ubus_process_notify_status(struct ubus_request *req, int id, struct
ubus_set_req_status(req, 0);
}
ubus_set_req_status(req, 0);
}
-void __hidden ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr
*hdr
, int fd)
+void __hidden ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr
_buf *buf
, int fd)
{
{
+ struct ubus_msghdr *hdr = &buf->hdr;
struct ubus_request *req;
int id = -1;
struct ubus_request *req;
int id = -1;
@@
-453,15
+458,21
@@
void __hidden ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr
}
if (id >= 0)
}
if (id >= 0)
- ubus_process_notify_status(req, id,
hdr
);
+ ubus_process_notify_status(req, id,
buf
);
else
else
- ubus_process_req_status(req,
hdr
);
+ ubus_process_req_status(req,
buf
);
break;
case UBUS_MSG_DATA:
req = ubus_find_request(ctx, hdr->seq, hdr->peer, &id);
if (req && (req->data_cb || req->raw_data_cb))
break;
case UBUS_MSG_DATA:
req = ubus_find_request(ctx, hdr->seq, hdr->peer, &id);
if (req && (req->data_cb || req->raw_data_cb))
- ubus_process_req_data(req,
hdr
);
+ ubus_process_req_data(req,
buf
);
break;
}
}
break;
}
}
+
+int __ubus_monitor(struct ubus_context *ctx, const char *type)
+{
+ blob_buf_init(&b, 0);
+ return ubus_invoke(ctx, UBUS_SYSTEM_OBJECT_MONITOR, type, b.head, NULL, NULL, 1000);
+}