X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=ubusd.c;h=ba1ff07720fa3da7cf5576eecfddc1c9530ba391;hp=6629720831348573ed7c6727036b67a2ea15ab68;hb=HEAD;hpb=47d75dd84af8ba6e9bac0d24861653e11796bdb0 diff --git a/ubusd.c b/ubusd.c index 6629720..ba1ff07 100644 --- a/ubusd.c +++ b/ubusd.c @@ -32,8 +32,15 @@ static struct ubus_msg_buf *ubus_msg_ref(struct ubus_msg_buf *ub) { - if (ub->refcount == ~0) - return ubus_msg_new(ub->data, ub->len, false); + struct ubus_msg_buf *new_ub; + if (ub->refcount == ~0) { + new_ub = ubus_msg_new(ub->data, ub->len, false); + if (!new_ub) + return NULL; + memcpy(&new_ub->hdr, &ub->hdr, sizeof(struct ubus_msghdr)); + new_ub->fd = ub->fd; + return new_ub; + } ub->refcount++; return ub; @@ -110,8 +117,15 @@ static int ubus_msg_writev(int fd, struct ubus_msg_buf *ub, int offset) } if (offset < sizeof(ub->hdr)) { - iov[0].iov_base = ((char *) &ub->hdr) + offset; - iov[0].iov_len = sizeof(ub->hdr) - offset; + struct ubus_msghdr hdr; + + hdr.version = ub->hdr.version; + hdr.type = ub->hdr.type; + hdr.seq = cpu_to_be16(ub->hdr.seq); + hdr.peer = cpu_to_be32(ub->hdr.peer); + + iov[0].iov_base = ((char *) &hdr) + offset; + iov[0].iov_len = sizeof(hdr) - offset; iov[1].iov_base = (char *) ub->data; iov[1].iov_len = ub->len; @@ -132,7 +146,7 @@ static void ubus_msg_enqueue(struct ubus_client *cl, struct ubus_msg_buf *ub) } /* takes the msgbuf reference */ -void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free) +void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub) { int written; @@ -141,22 +155,19 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free) if (!cl->tx_queue[cl->txq_cur]) { written = ubus_msg_writev(cl->sock.fd, ub, 0); - if (written >= ub->len + sizeof(ub->hdr)) - goto out; if (written < 0) written = 0; + if (written >= ub->len + sizeof(ub->hdr)) + return; + cl->txq_ofs = written; /* get an event once we can write to the socket again */ uloop_fd_add(&cl->sock, ULOOP_READ | ULOOP_WRITE | ULOOP_EDGE_TRIGGER); } ubus_msg_enqueue(cl, ub); - -out: - if (free) - ubus_msg_free(ub); } static struct ubus_msg_buf *ubus_msg_head(struct ubus_client *cl) @@ -275,6 +286,9 @@ retry: if (!cl->pending_msg) goto disconnect; + cl->hdrbuf.hdr.seq = be16_to_cpu(cl->hdrbuf.hdr.seq); + cl->hdrbuf.hdr.peer = be32_to_cpu(cl->hdrbuf.hdr.peer); + memcpy(&cl->pending_msg->hdr, &cl->hdrbuf.hdr, sizeof(cl->hdrbuf.hdr)); memcpy(cl->pending_msg->data, &cl->hdrbuf.data, sizeof(cl->hdrbuf.data)); } @@ -356,6 +370,7 @@ static int usage(const char *progname) { fprintf(stderr, "Usage: %s []\n" "Options: \n" + " -A : Set the path to ACL files\n" " -s : Set the unix domain socket to listen on\n" "\n", progname); return 1; @@ -378,11 +393,14 @@ int main(int argc, char **argv) openlog("ubusd", LOG_PID, LOG_DAEMON); uloop_init(); - while ((ch = getopt(argc, argv, "s:")) != -1) { + while ((ch = getopt(argc, argv, "A:s:")) != -1) { switch (ch) { case 's': ubus_socket = optarg; break; + case 'A': + ubusd_acl_dir = optarg; + break; default: return usage(argv[0]); }