X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=ubusd.c;h=5409b7f6ae57335423014d6aae0a7ee7650b3816;hp=89031053a2386700d1c9bf6f4eb36e8aa1d6b60f;hb=97ac89f9727d4fae1b2d63d2fc3b59e0d5d4bf65;hpb=996e16b2cb79ae3e46742285ee2728f3a166b42a diff --git a/ubusd.c b/ubusd.c index 8903105..5409b7f 100644 --- a/ubusd.c +++ b/ubusd.c @@ -17,6 +17,7 @@ #ifdef FreeBSD #include #endif +#include #include #include #include @@ -109,8 +110,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; @@ -135,14 +143,18 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free) { int written; + if (ub->hdr.type != UBUS_MSG_MONITOR) + ubusd_monitor_message(cl, ub, true); + 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)) + goto out; + cl->txq_ofs = written; /* get an event once we can write to the socket again */ @@ -178,6 +190,7 @@ static void handle_client_disconnect(struct ubus_client *cl) while (ubus_msg_head(cl)) ubus_msg_dequeue(cl); + ubusd_monitor_disconnect(cl); ubusd_proto_free_client(cl); if (cl->pending_msg_fd >= 0) close(cl->pending_msg_fd); @@ -241,7 +254,7 @@ retry: fd_buf.fd = -1; - iov.iov_base = &cl->hdrbuf + offset; + iov.iov_base = ((char *) &cl->hdrbuf) + offset; iov.iov_len = sizeof(cl->hdrbuf) - offset; if (cl->pending_msg_fd < 0) { @@ -270,6 +283,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)); } @@ -296,6 +312,7 @@ retry: cl->pending_msg_fd = -1; cl->pending_msg_offset = 0; cl->pending_msg = NULL; + ubusd_monitor_message(cl, ub, false); ubusd_proto_receive_message(cl, ub); goto retry; } @@ -350,11 +367,17 @@ 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; } +static void sighup_handler(int sig) +{ + ubusd_acl_load(); +} + int main(int argc, char **argv) { const char *ubus_socket = UBUS_UNIX_SOCKET; @@ -362,21 +385,26 @@ int main(int argc, char **argv) int ch; signal(SIGPIPE, SIG_IGN); + signal(SIGHUP, sighup_handler); + 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]); } } unlink(ubus_socket); - umask(0177); + umask(0111); server_fd.fd = usock(USOCK_UNIX | USOCK_SERVER | USOCK_NONBLOCK, ubus_socket, NULL); if (server_fd.fd < 0) { perror("usock"); @@ -384,6 +412,7 @@ int main(int argc, char **argv) goto out; } uloop_fd_add(&server_fd, ULOOP_READ | ULOOP_EDGE_TRIGGER); + ubusd_acl_load(); uloop_run(); unlink(ubus_socket);