test-policy.o \
test-policy-ns.o \
test-policy-priv.o \
+ test-send.o \
test-sync.o \
test-timeout.o
enum {
TEST_CREATE_BUS = 1 << 0,
TEST_CREATE_CONN = 1 << 1,
+ TEST_CREATE_CAN_FAIL = 1 << 2,
};
struct kdbus_test {
.func = kdbus_test_timeout,
.flags = TEST_CREATE_BUS,
},
+ {
+ .name = "send",
+ .desc = "send",
+ .func = kdbus_test_send,
+ .flags = TEST_CREATE_CONN | TEST_CREATE_CAN_FAIL,
+ },
{
.name = "sync-byebye",
.desc = "synchronous replies vs. BYEBYE",
_KDBUS_ATTACH_ALL,
_KDBUS_ATTACH_ALL, &s);
free(n);
- ASSERT_RETURN(ret == 0);
+ ASSERT_RETURN((ret == 0) || (t->flags & TEST_CREATE_CAN_FAIL));
asprintf(&env->buspath, "%s/%s/bus", args->root, s);
free(s);
}
ASSERT_RETURN(env->buspath);
env->conn = kdbus_hello(env->buspath, 0, NULL, 0);
- ASSERT_RETURN(env->conn);
+ ASSERT_RETURN(env->conn || (t->flags & TEST_CREATE_CAN_FAIL));
}
env->root = args->root;
int kdbus_test_policy(struct kdbus_test_env *env);
int kdbus_test_policy_ns(struct kdbus_test_env *env);
int kdbus_test_policy_priv(struct kdbus_test_env *env);
+int kdbus_test_send(struct kdbus_test_env *env);
int kdbus_test_sync_byebye(struct kdbus_test_env *env);
int kdbus_test_sync_reply(struct kdbus_test_env *env);
int kdbus_test_timeout(struct kdbus_test_env *env);
int64_t priority,
uint64_t dst_id,
uint64_t cmd_flags,
- int cancel_fd)
+ int cancel_fd,
+ int fds_count,
+ int fds[])
{
struct kdbus_cmd_send *cmd;
struct kdbus_msg *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));
+ size += fds_count > 0 ? KDBUS_ITEM_SIZE(sizeof(int) * fds_count) : 0;
if (dst_id == KDBUS_DST_ID_BROADCAST)
size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_bloom_filter)) + 64;
}
item = KDBUS_ITEM_NEXT(item);
+ if (fds_count > 0) {
+ item->type = KDBUS_ITEM_FDS;
+ item->size = KDBUS_ITEM_HEADER_SIZE + sizeof(int) * fds_count;
+ memcpy(&item->fds, fds, sizeof(int) * fds_count);
+ item = KDBUS_ITEM_NEXT(item);
+ }
+
size = sizeof(*cmd);
if (cancel_fd != -1)
size += KDBUS_ITEM_SIZE(sizeof(cancel_fd));
cmd = malloc(size);
+ if (!cmd) {
+ ret = -errno;
+ kdbus_printf("unable to malloc(%ld)!?\n", (long)size);
+ return ret;
+ }
cmd->size = size;
cmd->flags = cmd_flags;
cmd->msg_address = (uintptr_t)msg;
item = KDBUS_ITEM_NEXT(item);
}
+
ret = kdbus_cmd_send(conn->fd, cmd);
if (memfd >= 0)
close(memfd);
int kdbus_msg_send(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 fds_count, int fds[])
{
return __kdbus_msg_send(conn, name, cookie, flags, timeout, priority,
- dst_id, 0, -1);
+ dst_id, 0, -1, fds_count, fds);
}
int kdbus_msg_send_sync(const struct kdbus_conn *conn, const char *name,
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, cancel_fd);
+ dst_id, KDBUS_SEND_SYNC_REPLY, cancel_fd,
+ 0, NULL);
}
int kdbus_msg_send_reply(const struct kdbus_conn *conn,
char **path);
int kdbus_msg_send(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 fds_count, int fds[]);
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, int cancel_fd);
ret = RUN_UNPRIVILEGED_CONN(unpriv, env->buspath, ({
/* Try to talk using the ID */
ret = kdbus_msg_send(unpriv, NULL, 0xdeadbeef, 0, 0,
- 0, activator->id);
+ 0, activator->id, 0, NULL);
ASSERT_EXIT(ret == -ENXIO);
/* Try to talk to the name */
ret = kdbus_msg_send(unpriv, "foo.priv.activator",
0xdeadbeef, 0, 0, 0,
- KDBUS_DST_ID_NAME);
+ KDBUS_DST_ID_NAME, 0, NULL);
ASSERT_EXIT(ret == -EPERM);
}));
ASSERT_RETURN(ret >= 0);
cookie++;
ret = kdbus_msg_send(service, "foo.priv.activator", cookie,
- 0, 0, 0, KDBUS_DST_ID_NAME);
+ 0, 0, 0, KDBUS_DST_ID_NAME, 0, NULL);
ASSERT_RETURN(ret == 0);
ret = kdbus_starter_poll(activator);
/* Try to talk to the name */
ret = kdbus_msg_send(unpriv, "foo.priv.activator",
cookie, 0, 0, 0,
- KDBUS_DST_ID_NAME);
+ KDBUS_DST_ID_NAME, 0, NULL);
ASSERT_EXIT(ret == -EPERM);
}));
ASSERT_RETURN(ret >= 0);
cookie++;
ret = kdbus_msg_send(client, "foo.priv.activator", cookie,
- 0, 0, 0, KDBUS_DST_ID_NAME);
+ 0, 0, 0, KDBUS_DST_ID_NAME, 0, NULL);
ASSERT_RETURN(ret == 0);
ret = kdbus_msg_recv_poll(service, 100, &msg, NULL);
ASSERT_RETURN(ret == 0 && msg->cookie == cookie);
/* Try to talk to the name */
ret = kdbus_msg_send(unpriv, "foo.priv.activator",
cookie, 0, 0, 0,
- KDBUS_DST_ID_NAME);
+ KDBUS_DST_ID_NAME,
+ 0, NULL);
ASSERT_EXIT(ret == -EPERM);
}));
ASSERT_RETURN(ret >= 0);
/* Same user is able to TALK */
cookie++;
ret = kdbus_msg_send(client, "foo.priv.activator", cookie,
- 0, 0, 0, KDBUS_DST_ID_NAME);
+ 0, 0, 0, KDBUS_DST_ID_NAME, 0, NULL);
ASSERT_RETURN(ret == 0);
ret = kdbus_msg_recv_poll(service, 100, &msg, NULL);
ASSERT_RETURN(ret == 0 && msg->cookie == cookie);
/* Try to talk to the name */
ret = kdbus_msg_send(unpriv, "foo.priv.activator",
cookie, 0, 0, 0,
- KDBUS_DST_ID_NAME);
+ KDBUS_DST_ID_NAME,
+ 0, NULL);
ASSERT_EXIT(ret == 0);
}));
ASSERT_RETURN(ret >= 0);
ASSERT_RETURN(ret == 0);
ret = kdbus_msg_send(env->conn, "foo.test.activator", 0xdeafbeef,
- 0, 0, 0, KDBUS_DST_ID_NAME);
+ 0, 0, 0, KDBUS_DST_ID_NAME, 0, NULL);
ASSERT_RETURN(ret == 0);
fds[0].fd = activator->fd;
cookie = 0;
ret = kdbus_msg_send(conn_b, NULL, 0xc0000000 | cookie, 0, 0, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_RETURN(ret == 0);
fds[0].fd = conn_a->fd;
ASSERT_RETURN(ret == 0);
ret = kdbus_msg_send(conn_a, NULL,
0xc0000000 | cookie++,
- 0, 0, 0, conn_b->id);
+ 0, 0, 0, conn_b->id, 0, NULL);
ASSERT_RETURN(ret == 0);
}
ASSERT_RETURN(ret == 0);
ret = kdbus_msg_send(conn_b, NULL,
0xc0000000 | cookie++,
- 0, 0, 0, conn_a->id);
+ 0, 0, 0, conn_a->id, 0, NULL);
ASSERT_RETURN(ret == 0);
}
/* send over 1st connection */
ret = kdbus_msg_send(env->conn, NULL, 0, 0, 0, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_RETURN(ret == 0);
/* say byebye on the 2nd, which must fail */
conn = kdbus_hello(env->buspath, 0, NULL, 0);
ASSERT_RETURN(conn);
- ret = kdbus_msg_send(env->conn, NULL, 0x12345678, 0, 0, 0, conn->id);
+ ret = kdbus_msg_send(env->conn, NULL, 0x12345678, 0, 0, 0, conn->id,
+ 0, NULL);
ASSERT_RETURN(ret == 0);
ret = kdbus_msg_recv(conn, &msg, NULL);
~KDBUS_ATTACH_TIMESTAMP);
ASSERT_RETURN(ret == 0);
- ret = kdbus_msg_send(env->conn, NULL, 0x12345678, 0, 0, 0, conn->id);
+ ret = kdbus_msg_send(env->conn, NULL, 0x12345678, 0, 0, 0, conn->id,
+ 0, NULL);
ASSERT_RETURN(ret == 0);
ret = kdbus_msg_recv(conn, &msg, NULL);
*/
cookie++;
ret = kdbus_msg_send(conn_src, NULL, cookie, 0, 0, 0,
- conn_dst->id);
+ conn_dst->id, 0, NULL);
ASSERT_RETURN(ret == 0);
ret = waitpid(pid, &status, 0);
/* send over 1st connection */
ret = kdbus_msg_send(sender, NULL, cookie, 0, 0, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_RETURN(ret == 0);
/* Make sure that we do not get our own broadcasts */
/* Msgs that expect a reply must have timeout and cookie */
ret = kdbus_msg_send(sender, NULL, 0, KDBUS_MSG_EXPECT_REPLY,
- 0, 0, conn->id);
+ 0, 0, conn->id, 0, NULL);
ASSERT_RETURN(ret == -EINVAL);
/* Faked replies with a valid reply cookie are rejected */
{
struct kdbus_conn *a, *b;
uint64_t cookie = 0;
+ int ret;
a = kdbus_hello(env->buspath, 0, NULL, 0);
b = kdbus_hello(env->buspath, 0, NULL, 0);
ASSERT_RETURN(a && b);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, 25, a->id) == 0);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, -600, a->id) == 0);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, 10, a->id) == 0);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, -35, a->id) == 0);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, -100, a->id) == 0);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, 20, a->id) == 0);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, -15, a->id) == 0);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, -800, a->id) == 0);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, -150, a->id) == 0);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, 10, a->id) == 0);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, -800, a->id) == 0);
- ASSERT_RETURN(kdbus_msg_send(b, NULL, ++cookie, 0, 0, -10, a->id) == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, 25, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, -600, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, 10, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, -35, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, -100, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, 20, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, -15, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, -800, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, -150, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, 10, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, -800, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, -10, a->id, 0, NULL);
+ ASSERT_RETURN(ret == 0);
ASSERT_RETURN(msg_recv_prio(a, -200, -800) == 0);
ASSERT_RETURN(msg_recv_prio(a, -100, -800) == 0);
* Now the reader queue is full with kernel notfications,
* but as a user we still have room to push our messages.
*/
- ret = kdbus_msg_send(conn, NULL, 0xdeadbeef, 0, 0, 0, reader->id);
+ ret = kdbus_msg_send(conn, NULL, 0xdeadbeef, 0, 0, 0, reader->id,
+ 0, NULL);
ASSERT_RETURN(ret == 0);
/* More ID kernel notifications that will be lost */
for (i = 0; i < KDBUS_CONN_MAX_MSGS; i++) {
ret = kdbus_msg_send(sender, "foo.test.activator",
cookie++, 0, 0, 0,
- KDBUS_DST_ID_NAME);
+ KDBUS_DST_ID_NAME,
+ 0, NULL);
if (ret < 0)
break;
activator_msgs_count++;
/* Good, activator queue is full now */
/* ENXIO on direct send (activators can never be addressed by ID) */
- ret = kdbus_msg_send(conn, NULL, cookie++, 0, 0, 0, activator->id);
+ ret = kdbus_msg_send(conn, NULL, cookie++, 0, 0, 0, activator->id,
+ 0, NULL);
ASSERT_RETURN(ret == -ENXIO);
/* can't queue more */
ret = kdbus_msg_send(conn, "foo.test.activator", cookie++,
- 0, 0, 0, KDBUS_DST_ID_NAME);
+ 0, 0, 0, KDBUS_DST_ID_NAME, 0, NULL);
ASSERT_RETURN(ret == -ENOBUFS);
/* no match installed, so the broadcast will not inc dropped_msgs */
ret = kdbus_msg_send(sender, NULL, cookie++, 0, 0, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_RETURN(ret == 0);
/* Check activator queue */
/* Consume the connection pool memory */
for (i = 0; i < KDBUS_CONN_MAX_MSGS; i++) {
ret = kdbus_msg_send(sender, NULL,
- cookie++, 0, 0, 0, conn->id);
+ cookie++, 0, 0, 0, conn->id, 0, NULL);
if (ret < 0)
break;
}
/* This one is lost but it is not accounted */
ret = kdbus_msg_send(sender, NULL,
- cookie++, 0, 0, 0, conn->id);
+ cookie++, 0, 0, 0, conn->id, 0, NULL);
ASSERT_RETURN(ret == -ENOBUFS);
/* Acquire the name again */
ret = kdbus_msg_send(conn, NULL, cookie++,
KDBUS_MSG_EXPECT_REPLY,
100000000ULL, 0,
- connections[i]->id);
+ connections[i]->id,
+ 0, NULL);
if (ret < 0)
break;
* no further requests are allowed
*/
ret = kdbus_msg_send(conn, NULL, cookie++, KDBUS_MSG_EXPECT_REPLY,
- 1000000000ULL, 0, connections[8]->id);
+ 1000000000ULL, 0, connections[8]->id, 0, NULL);
ASSERT_RETURN(ret == -EMLINK);
for (i = 0; i < 9; i++)
ASSERT_RETURN(ret == -ENOBUFS);
/* We still can pass small messages */
- ret = kdbus_msg_send(b, NULL, cookie++, 0, 0, 0, c->id);
+ ret = kdbus_msg_send(b, NULL, cookie++, 0, 0, 0, c->id, 0, NULL);
ASSERT_RETURN(ret == 0);
for (i = size; i < (POOL_SIZE / 2 / 3); i += size) {
ret = kdbus_fill_conn_queue(b, a->id, KDBUS_CONN_MAX_MSGS);
ASSERT_RETURN(ret == KDBUS_CONN_MAX_MSGS);
- ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, 0, a->id);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, 0, a->id, 0, NULL);
ASSERT_RETURN(ret == -ENOBUFS);
for (i = 0; i < KDBUS_CONN_MAX_MSGS; ++i) {
ret = kdbus_fill_conn_queue(b, a->id, KDBUS_CONN_MAX_MSGS + 1);
ASSERT_RETURN(ret == KDBUS_CONN_MAX_MSGS);
- ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, 0, a->id);
+ ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, 0, a->id, 0, NULL);
ASSERT_RETURN(ret == -ENOBUFS);
kdbus_conn_free(a);
*/
ret = kdbus_msg_send(unpriv_conn, NULL, cookie, 0, 0,
- 0, conn->id);
+ 0, conn->id, 0, NULL);
ASSERT_EXIT(ret == 0);
/*
cookie++;
ret = kdbus_msg_send(userns_conn, NULL, cookie,
- 0, 0, 0, conn->id);
+ 0, 0, 0, conn->id, 0, NULL);
ASSERT_EXIT(ret == 0);
/* Parent did send */
* Sending to unprivileged connections a unicast
*/
ret = kdbus_msg_send(conn, NULL, 0xdeadbeef, 0, 0,
- 0, unpriv_conn_id);
+ 0, unpriv_conn_id, 0, NULL);
ASSERT_RETURN(ret == 0);
/* signal to child that is in its userns */
* connections a unicast
*/
ret = kdbus_msg_send(conn, NULL, 0xdeadbeef, 0, 0,
- 0, userns_conn_id);
+ 0, userns_conn_id, 0, NULL);
ASSERT_RETURN(ret == 0);
/*
* Sending to unprivileged connections a broadcast
*/
ret = kdbus_msg_send(conn, NULL, 0xdeadbeef, 0, 0,
- 0, KDBUS_DST_ID_BROADCAST);
+ 0, KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_RETURN(ret == 0);
ret = kdbus_name_acquire(monitor, "foo.bar.baz", NULL);
ASSERT_RETURN(ret == -EOPNOTSUPP);
- ret = kdbus_msg_send(env->conn, NULL, cookie, 0, 0, 0, conn->id);
+ ret = kdbus_msg_send(env->conn, NULL, cookie, 0, 0, 0, conn->id,
+ 0, NULL);
ASSERT_RETURN(ret == 0);
/* the recipient should have gotten the message */
cookie++;
ret = kdbus_msg_send(env->conn, NULL, cookie, 0, 0, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_RETURN(ret == 0);
/* The monitor should get the message. */
cookie++;
ret = kdbus_msg_send(env->conn, NULL, cookie, 0, 0, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_RETURN(ret == 0);
ret = kdbus_msg_recv_poll(monitor, 100, &msg, &offset);
cookie++;
ret = kdbus_msg_send(env->conn, NULL, cookie, 0, 0, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_RETURN(ret == 0);
ret = kdbus_msg_recv_poll(monitor, 100, &msg, &offset);
break;
ret = kdbus_msg_send(conn_db[i], name, cookie++,
- 0, 0, 0, dst_id);
+ 0, 0, 0, dst_id, 0, NULL);
if (ret < 0) {
/*
* Receivers are not reading their messages,
* EXIT_FAILURE.
*/
ret = kdbus_msg_send(conn_src, NULL, cookie,
- 0, 0, 0, conn_db[0]->id);
+ 0, 0, 0, conn_db[0]->id, 0, NULL);
ASSERT_EXIT(ret == child_status);
ret = kdbus_msg_recv_poll(conn_src, 100, NULL, NULL);
}
ret = kdbus_msg_send(conn_db[0], NULL, ++cookie,
- 0, 0, 0, msg->src_id);
+ 0, 0, 0, msg->src_id, 0, NULL);
/*
* parent_status is checked against send operations,
* on failures always return TEST_ERR.
ASSERT_EXIT(ret == 0);
ret = kdbus_msg_send(conn_src, name, 0xabcd1234,
- 0, 0, 0, KDBUS_DST_ID_NAME);
+ 0, 0, 0, KDBUS_DST_ID_NAME, 0, NULL);
kdbus_conn_free(conn_src);
_exit(ret == expected_status ? EXIT_SUCCESS : EXIT_FAILURE);
ret = RUN_UNPRIVILEGED_CONN(unpriv, bus, ({
ret = kdbus_msg_send(unpriv, NULL,
expected_cookie, 0, 0, 0,
- conn_dst->id);
+ conn_dst->id, 0, NULL);
ASSERT_EXIT(ret == child_status);
}));
ASSERT_RETURN(ret >= 0);
/* Use expected_cookie since 'msg' might be NULL */
ret = kdbus_msg_send(child, NULL, expected_cookie + 1,
- 0, 0, 0, KDBUS_DST_ID_BROADCAST);
+ 0, 0, 0, KDBUS_DST_ID_BROADCAST,
+ 0, NULL);
ASSERT_EXIT(ret == 0);
kdbus_msg_free(msg);
ret = kdbus_msg_send(child_2, NULL,
expected_cookie, 0, 0, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST,
+ 0, NULL);
ASSERT_RETURN(ret == 0);
/* Use a little bit high time */
ret = kdbus_msg_send(child_2, NULL,
expected_cookie, 0, 0, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST,
+ 0, NULL);
ASSERT_EXIT(ret == 0);
/* Use a little bit high time */
ret = kdbus_msg_send(unpriv, NULL, 0xdeadbeef,
KDBUS_MSG_EXPECT_REPLY,
5000000000ULL, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST,
+ 0, NULL);
ASSERT_EXIT(ret == -ENOTUNIQ);
}));
ASSERT_RETURN(ret == 0);
++expected_cookie;
ret = kdbus_msg_send(owner_a, NULL, expected_cookie, 0,
- 0, 0, KDBUS_DST_ID_BROADCAST);
+ 0, 0, KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_RETURN(ret == 0);
ret = kdbus_msg_recv_poll(owner_b, 100, &msg, NULL);
ret = kdbus_msg_send(unpriv_owner, NULL,
expected_cookie,
0, 0, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST,
+ 0, NULL);
ASSERT_EXIT(ret == 0);
/*
NULL);
ASSERT_EXIT(ret >= 0);
ret = kdbus_msg_send(unpriv, NULL, expected_cookie,
- 0, 0, 0, KDBUS_DST_ID_BROADCAST);
+ 0, 0, 0, KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_EXIT(ret == 0);
}));
ASSERT_RETURN(ret == 0);
NULL);
ASSERT_EXIT(ret >= 0);
ret = kdbus_msg_send(unpriv, NULL, expected_cookie,
- 0, 0, 0, KDBUS_DST_ID_BROADCAST);
+ 0, 0, 0, KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_EXIT(ret == 0);
}));
ASSERT_RETURN(ret == 0);
conn = kdbus_hello(env->buspath, 0, NULL, 0);
ASSERT_RETURN(conn);
- ret = kdbus_msg_send(conn, "com.example.b", 0xdeadbeef, 0, 0, 0, 0);
+ ret = kdbus_msg_send(conn, "com.example.b", 0xdeadbeef, 0, 0, 0, 0,
+ 0, NULL);
ASSERT_EXIT(ret >= 0);
ret = kdbus_msg_recv_poll(conn_b, 300, NULL, NULL);
ret = RUN_UNPRIVILEGED_CONN(unpriv, env->buspath, ({
ret = kdbus_msg_send(unpriv, "com.example.b", 0xdeadbeef, 0, 0,
- 0, 0);
+ 0, 0, 0, NULL);
ASSERT_EXIT(ret == -EPERM);
}));
ASSERT_RETURN(ret >= 0);
ASSERT_EXIT(ret >= 0);
ret = kdbus_msg_send(unpriv, "com.example.c", 0xdeadbeef, 0, 0,
- 0, 0);
+ 0, 0, 0, NULL);
ASSERT_EXIT(ret >= 0);
ret = kdbus_msg_recv_poll(owner, 100, NULL, NULL);
ASSERT_EXIT(ret >= 0);
ret = RUN_UNPRIVILEGED_CONN(unpriv, env->buspath, ({
ret = kdbus_msg_send(unpriv, "com.example.b", 0xdeadbeef, 0, 0,
- 0, 0);
+ 0, 0, 0, NULL);
ASSERT_EXIT(ret >= 0);
}));
ASSERT_RETURN(ret >= 0);
ret = RUN_UNPRIVILEGED_CONN(unpriv, env->buspath, ({
ret = kdbus_msg_send(unpriv, "com.example.b", 0xdeadbeef, 0, 0,
- 0, 0);
+ 0, 0, 0, NULL);
ASSERT_EXIT(ret >= 0);
}));
ASSERT_RETURN(ret >= 0);
ret = RUN_UNPRIVILEGED_CONN(unpriv, env->buspath, ({
ret = kdbus_msg_send(unpriv, "com.example.b", 0xdeadbeef, 0, 0,
- 0, 0);
+ 0, 0, 0, NULL);
ASSERT_EXIT(ret >= 0);
}));
ASSERT_RETURN(ret >= 0);
ret = RUN_UNPRIVILEGED_CONN(unpriv, env->buspath, ({
ret = kdbus_msg_send(unpriv, "com.example.b", 0xdeadbeef, 0, 0,
- 0, 0);
+ 0, 0, 0, NULL);
ASSERT_EXIT(ret == -EPERM);
}));
ASSERT_RETURN(ret >= 0);
ret = RUN_UNPRIVILEGED_CONN(unpriv, env->buspath, ({
ret = kdbus_msg_send(unpriv, "com.example.b", 0xdeadbeef, 0, 0,
- 0, 0);
+ 0, 0, 0, NULL);
ASSERT_EXIT(ret >= 0);
}));
ASSERT_RETURN(ret >= 0);
ret = RUN_UNPRIVILEGED_CONN(unpriv, env->buspath, ({
ret = kdbus_msg_send(unpriv, "com.example.b", 0xdeadbeef, 0, 0,
- 0, 0);
+ 0, 0, 0, NULL);
ASSERT_EXIT(ret >= 0);
ret = kdbus_msg_recv_poll(conn_b, 100, NULL, NULL);
ASSERT_RETURN(ret == 0);
ret = kdbus_msg_send(unpriv, "com.example.b", 0xdeadbeef, 0, 0,
- 0, 0);
+ 0, 0, 0, NULL);
ASSERT_EXIT(ret == -EPERM);
}));
ASSERT_RETURN(ret >= 0);
ASSERT_RETURN(unpriv);
ret = kdbus_msg_send(unpriv, "com.example.c", 0xdeadbeef, 0, 0,
- 0, 0);
+ 0, 0, 0, NULL);
ASSERT_EXIT(ret >= 0);
ret = kdbus_msg_recv_poll(owner, 100, NULL, NULL);
kdbus_conn_free(conn);
ret = kdbus_msg_send(unpriv, "com.example.c", 0xdeadbeef, 0, 0,
- 0, 0);
+ 0, 0, 0, NULL);
ASSERT_EXIT(ret == -EPERM);
kdbus_conn_free(unpriv);
--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <fcntl.h>
+#include <stdlib.h>
+/* Use in conjunction with test-kdbus-daemon */
+
+#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <errno.h>
+#include <assert.h>
+#include <poll.h>
+#include <sys/ioctl.h>
+
+#include "kdbus-test.h"
+#include "kdbus-util.h"
+#include "kdbus-enum.h"
+
+int get_file(const char *fname, int flags, const char *content)
+{
+ FILE *f;
+
+ if (access(fname, F_OK) < 0) {
+ f = fopen(fname, "w");
+ if (!f)
+ return -1;
+ fprintf(f, "%s\n", content);
+ fclose(f);
+ }
+
+ return open(fname, flags);
+}
+
+int kdbus_test_send(struct kdbus_test_env *env)
+{
+ int ret;
+ int serial = 1;
+ int fds[3];
+ size_t i;
+
+ if (!env->conn)
+ return EXIT_FAILURE;
+
+ fds[0] = get_file("/tmp/kdbus-test-send.rd", O_RDONLY, "foo");
+ fds[1] = get_file("/tmp/kdbus-test-send.wr", O_WRONLY, "bar");
+ fds[2] = get_file("/tmp/kdbus-test-send.rdwr", O_RDWR, "baz");
+
+ for (i = 0; i < ELEMENTSOF(fds); i++) {
+ if (fds[i] < 0) {
+ fprintf(stderr, "Unable to open data/fileN file(s)\n");
+ return EXIT_FAILURE;
+ }
+ }
+
+ ret = kdbus_msg_send(env->conn, "com.example.kdbus-test", serial++,
+ 0, 0, 0, 0, 0, NULL);
+ if (ret < 0)
+ fprintf(stderr, "error sending simple message: %d (%m)\n",
+ ret);
+
+ ret = kdbus_msg_send(env->conn, "com.example.kdbus-test", serial++,
+ 0, 0, 0, 0, 1, fds);
+ if (ret < 0)
+ fprintf(stderr, "error sending message with 1 fd: %d (%m)\n",
+ ret);
+
+ ret = kdbus_msg_send(env->conn, "com.example.kdbus-test", serial++,
+ 0, 0, 0, 0, 2, fds);
+ if (ret < 0)
+ fprintf(stderr, "error sending message with 2 fds: %d (%m)\n",
+ ret);
+
+ ret = kdbus_msg_send(env->conn, "com.example.kdbus-test", serial++,
+ 0, 0, 0, 0, 3, fds);
+ if (ret < 0)
+ fprintf(stderr, "error sending message with 3 fds: %d (%m)\n",
+ ret);
+
+ for (i = 0; i < ELEMENTSOF(fds); i++)
+ close(fds[i]);
+
+ return EXIT_SUCCESS;
+}
}
ret = kdbus_msg_send(conn_dst, NULL, cookie, 0, 0, 0,
- KDBUS_DST_ID_BROADCAST);
+ KDBUS_DST_ID_BROADCAST, 0, NULL);
ASSERT_RETURN(ret == 0);
cookie++;
ASSERT_RETURN(kdbus_msg_send(conn_b, NULL, cookie,
KDBUS_MSG_EXPECT_REPLY,
(i + 1) * 100ULL * 1000000ULL, 0,
- conn_a->id) == 0);
+ conn_a->id, 0, NULL) == 0);
expected |= 1ULL << cookie;
}