fix a copy & paste bug
[project/ubus.git] / ubusd.c
diff --git a/ubusd.c b/ubusd.c
index bcc8603..aa72351 100644 (file)
--- a/ubusd.c
+++ b/ubusd.c
@@ -17,6 +17,7 @@
 #ifdef FreeBSD
 #include <sys/param.h>
 #endif
+#include <syslog.h>
 #include <signal.h>
 #include <stdio.h>
 #include <unistd.h>
 
 #include "ubusd.h"
 
-static struct ubus_msg_buf *ubus_msg_unshare(struct ubus_msg_buf *ub)
-{
-       ub = realloc(ub, sizeof(*ub) + ub->len);
-       if (!ub)
-               return NULL;
-
-       ub->refcount = 1;
-       memcpy(ub + 1, ub->data, ub->len);
-       ub->data = (void *) (ub + 1);
-       return ub;
-}
-
 static struct ubus_msg_buf *ubus_msg_ref(struct ubus_msg_buf *ub)
 {
        if (ub->refcount == ~0)
-               return ubus_msg_unshare(ub);
+               return ubus_msg_new(ub->data, ub->len, false);
 
        ub->refcount++;
        return ub;
@@ -253,7 +242,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) {
@@ -367,6 +356,11 @@ static int usage(const char *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;
@@ -374,7 +368,9 @@ 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) {
@@ -388,7 +384,7 @@ int main(int argc, char **argv)
        }
 
        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");
@@ -396,6 +392,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);