ubus/lua: pass notification name to callback
[project/ubus.git] / ubusd.c
diff --git a/ubusd.c b/ubusd.c
index 5409b7f..ba1ff07 100644 (file)
--- a/ubusd.c
+++ b/ubusd.c
 
 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;
@@ -139,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;
 
@@ -153,7 +160,7 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free)
                        written = 0;
 
                if (written >= ub->len + sizeof(ub->hdr))
-                       goto out;
+                       return;
 
                cl->txq_ofs = written;
 
@@ -161,10 +168,6 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free)
                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)