test: add cancel_fd parameter to kdbus_msg_send_sync()
authorDaniel Mack <daniel@zonque.org>
Fri, 19 Dec 2014 18:25:14 +0000 (19:25 +0100)
committerDaniel Mack <daniel@zonque.org>
Fri, 19 Dec 2014 18:32:17 +0000 (19:32 +0100)
Add another parameter to kdbus_msg_send_sync() which should be set
to -1 if unused. If >= 0, it will cause the SEND cmd ioctl to carry
an item of type KDBUS_ITEM_CANCEL_FD, and put the given value into
it.

Signed-off-by: Daniel Mack <daniel@zonque.org>
test/kdbus-util.c
test/kdbus-util.h
test/test-fd.c
test/test-sync.c

index b9bd93bfb20a8cc7eb02fb340bc5d952de88e0d8..7bf3649a92a16a4ca0d6c4ab79562b1b9a431c63 100644 (file)
@@ -456,9 +456,10 @@ static int __kdbus_msg_send(const struct kdbus_conn *conn,
                            uint64_t timeout,
                            int64_t priority,
                            uint64_t dst_id,
-                           uint64_t cmd_flags)
+                           uint64_t cmd_flags,
+                           int cancel_fd)
 {
-       struct kdbus_cmd_send cmd = {};
+       struct kdbus_cmd_send *cmd;
        struct kdbus_msg *msg;
        const char ref1[1024 * 128 + 3] = "0123456789_0";
        const char ref2[] = "0123456789_1";
@@ -468,7 +469,7 @@ static int __kdbus_msg_send(const struct kdbus_conn *conn,
        int memfd = -1;
        int ret;
 
-       size = sizeof(struct kdbus_msg);
+       size = sizeof(*msg);
        size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec));
        size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec));
        size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec));
@@ -566,11 +567,25 @@ static int __kdbus_msg_send(const struct kdbus_conn *conn,
        }
        item = KDBUS_ITEM_NEXT(item);
 
-       cmd.size = sizeof(cmd);
-       cmd.flags = cmd_flags;
-       cmd.msg_address = (uintptr_t)msg;
+       size = sizeof(*cmd);
+       if (cancel_fd != -1)
+               size += KDBUS_ITEM_SIZE(sizeof(cancel_fd));
 
-       ret = ioctl(conn->fd, KDBUS_CMD_SEND, &cmd);
+       cmd = malloc(size);
+       cmd->size = size;
+       cmd->flags = cmd_flags;
+       cmd->msg_address = (uintptr_t)msg;
+
+       item = cmd->items;
+
+       if (cancel_fd != -1) {
+               item->type = KDBUS_ITEM_CANCEL_FD;
+               item->size = KDBUS_ITEM_HEADER_SIZE + sizeof(cancel_fd);
+               item->fds[0] = cancel_fd;
+               item = KDBUS_ITEM_NEXT(item);
+       }
+
+       ret = ioctl(conn->fd, KDBUS_CMD_SEND, cmd);
        if (memfd >= 0)
                close(memfd);
 
@@ -583,18 +598,19 @@ static int __kdbus_msg_send(const struct kdbus_conn *conn,
        if (cmd_flags & KDBUS_SEND_SYNC_REPLY) {
                struct kdbus_msg *reply;
 
-               kdbus_printf("SYNC REPLY @offset %llu:\n", cmd.reply.offset);
-               reply = (struct kdbus_msg *)(conn->buf + cmd.reply.offset);
+               kdbus_printf("SYNC REPLY @offset %llu:\n", cmd->reply.offset);
+               reply = (struct kdbus_msg *)(conn->buf + cmd->reply.offset);
                kdbus_msg_dump(conn, reply);
 
                kdbus_msg_free(reply);
 
-               ret = kdbus_free(conn, cmd.reply.offset);
+               ret = kdbus_free(conn, cmd->reply.offset);
                if (ret < 0)
                        return ret;
        }
 
        free(msg);
+       free(cmd);
 
        return 0;
 }
@@ -604,15 +620,15 @@ int kdbus_msg_send(const struct kdbus_conn *conn, const char *name,
                   int64_t priority, uint64_t dst_id)
 {
        return __kdbus_msg_send(conn, name, cookie, flags, timeout, priority,
-                               dst_id, 0);
+                               dst_id, 0, -1);
 }
 
 int kdbus_msg_send_sync(const struct kdbus_conn *conn, const char *name,
                        uint64_t cookie, uint64_t flags, uint64_t timeout,
-                       int64_t priority, uint64_t dst_id)
+                       int64_t priority, uint64_t dst_id, int cancel_fd)
 {
        return __kdbus_msg_send(conn, name, cookie, flags, timeout, priority,
-                               dst_id, KDBUS_SEND_SYNC_REPLY);
+                               dst_id, KDBUS_SEND_SYNC_REPLY, cancel_fd);
 }
 
 static char *msg_id(uint64_t id, char *buf)
index ab6380aafcc8ac55a0cbe43806741ff5eb05e90d..a568fc677eebb1b2adc92ec190f3d2132e46eb54 100644 (file)
@@ -170,7 +170,7 @@ int kdbus_msg_send(const struct kdbus_conn *conn, const char *name,
                   int64_t priority, uint64_t dst_id);
 int kdbus_msg_send_sync(const struct kdbus_conn *conn, const char *name,
                        uint64_t cookie, uint64_t flags, uint64_t timeout,
-                       int64_t priority, uint64_t dst_id);
+                       int64_t priority, uint64_t dst_id, int cancel_fd);
 struct kdbus_conn *kdbus_hello(const char *path, uint64_t hello_flags,
                               const struct kdbus_item *item,
                               size_t item_size);
index 498232964993d755ef5232c4e072a015ba24dcce..4cd7e7daac8e251b74f79b8a7ff0263d20925147 100644 (file)
@@ -389,7 +389,7 @@ static int kdbus_test_no_fds(struct kdbus_test_env *env,
                cookie++;
                ret = kdbus_msg_send_sync(conn_dst, NULL, cookie,
                                          KDBUS_MSG_EXPECT_REPLY,
-                                         5000000000ULL, 0, conn_src->id);
+                                         5000000000ULL, 0, conn_src->id, -1);
                ASSERT_EXIT(ret == -EREMOTEIO);
 
                cookie++;
index 8b55ad85cfa5f3e886a40acef54ee4b2122a8896..311b163f8c3753feebbe726e10c9a9bd7a4e1649 100644 (file)
@@ -95,7 +95,7 @@ static int interrupt_sync(struct kdbus_conn *conn_src,
 
                ret = kdbus_msg_send_sync(conn_dst, NULL, cookie,
                                          KDBUS_MSG_EXPECT_REPLY,
-                                         100000000ULL, 0, conn_src->id);
+                                         100000000ULL, 0, conn_src->id, -1);
                ASSERT_EXIT(ret == -ETIMEDOUT);
 
                _exit(EXIT_SUCCESS);
@@ -164,7 +164,7 @@ int kdbus_test_sync_reply(struct kdbus_test_env *env)
 
        ret = kdbus_msg_send_sync(conn_b, NULL, cookie,
                                  KDBUS_MSG_EXPECT_REPLY,
-                                 5000000000ULL, 0, conn_a->id);
+                                 5000000000ULL, 0, conn_a->id, -1);
 
        pthread_join(thread, (void *) &status);
        ASSERT_RETURN(status == 0);
@@ -228,7 +228,7 @@ int kdbus_test_sync_byebye(struct kdbus_test_env *env)
 
        ret = kdbus_msg_send_sync(conn_b, NULL, cookie,
                                  KDBUS_MSG_EXPECT_REPLY,
-                                 5000000000ULL, 0, conn_a->id);
+                                 5000000000ULL, 0, conn_a->id, -1);
 
        ASSERT_RETURN(ret == -ECONNRESET);
 
@@ -245,7 +245,7 @@ int kdbus_test_sync_byebye(struct kdbus_test_env *env)
 
        ret = kdbus_msg_send_sync(conn_b, NULL, cookie,
                                  KDBUS_MSG_EXPECT_REPLY,
-                                 5000000000ULL, 0, conn_a->id);
+                                 5000000000ULL, 0, conn_a->id, -1);
 
        ASSERT_RETURN(ret == -EPIPE);