ucode: check for errors in ftruncate()
[project/udebug.git] / ring.c
diff --git a/ring.c b/ring.c
index 8a7e27fc7eb5c6b7d3abbfb545ddd20be878c494..4adcfda6cbf82423e700961fcdd2e2fbe2dbdc85 100644 (file)
--- a/ring.c
+++ b/ring.c
@@ -44,8 +44,10 @@ struct client_ring *client_ring_alloc(struct client *cl)
        struct client_ring *r;
        size_t meta_len;
 
-       if (cl->rx_fd < 0)
+       if (cl->rx_fd < 0) {
+               DC(2, cl, "missing file descriptor");
                return NULL;
+       }
 
        meta_len = blob_pad_len(&cl->rx_buf.data);
        r = calloc_a(sizeof(*r), &meta, meta_len);
@@ -53,6 +55,7 @@ struct client_ring *client_ring_alloc(struct client *cl)
 
        blobmsg_parse_attr(policy, __RING_ATTR_MAX, tb, meta);
        if (!tb[RING_ATTR_NAME]) {
+               DC(2, cl, "missing ring name");
                close(cl->rx_fd);
                free(r);
                return NULL;
@@ -64,6 +67,7 @@ struct client_ring *client_ring_alloc(struct client *cl)
        r->cl = cl;
        r->id = msg->id;
        r->fd = cl->rx_fd;
+       cl->rx_fd = -1;
        r->ring_size = msg->ring_size;
        r->data_size = msg->data_size;
        list_add_tail(&r->list, &cl->bufs);