From 13019ef5ea284b03a74f25897a49fa5670974568 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 10 May 2013 19:58:05 +0200 Subject: bus: fix test-bus-memfd --- src/libsystemd-bus/bus-kernel.c | 8 ++++---- src/libsystemd-bus/kdbus.h | 2 +- src/libsystemd-bus/test-bus-memfd.c | 32 ++++++++++---------------------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c index aecf408645..3fb5822a8f 100644 --- a/src/libsystemd-bus/bus-kernel.c +++ b/src/libsystemd-bus/bus-kernel.c @@ -45,7 +45,7 @@ #define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data) #define KDBUS_ITEM_SIZE(s) ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE) -#define KDBUS_BUFFER_SIZE (4*1024*1024) +#define KDBUS_POOL_SIZE (4*1024*1024) static int parse_unique_name(const char *s, uint64_t *id) { int r; @@ -292,7 +292,7 @@ int bus_kernel_take_fd(sd_bus *b) { return -EINVAL; if (!b->kdbus_buffer) { - b->kdbus_buffer = mmap(NULL, KDBUS_BUFFER_SIZE, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + b->kdbus_buffer = mmap(NULL, KDBUS_POOL_SIZE, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); if (b->kdbus_buffer == MAP_FAILED) { b->kdbus_buffer = NULL; return -errno; @@ -310,10 +310,10 @@ int bus_kernel_take_fd(sd_bus *b) { KDBUS_HELLO_ATTACH_SECLABEL| KDBUS_HELLO_ATTACH_AUDIT; - hello->items[0].type = KDBUS_HELLO_BUFFER; + hello->items[0].type = KDBUS_HELLO_POOL; hello->items[0].size = KDBUS_ITEM_HEADER_SIZE + sizeof(struct kdbus_vec); hello->items[0].vec.address = (uint64_t) b->kdbus_buffer; - hello->items[0].vec.size = KDBUS_BUFFER_SIZE; + hello->items[0].vec.size = KDBUS_POOL_SIZE; r = ioctl(b->input_fd, KDBUS_CMD_HELLO, hello); if (r < 0) diff --git a/src/libsystemd-bus/kdbus.h b/src/libsystemd-bus/kdbus.h index bb339ae69c..1f855b040b 100644 --- a/src/libsystemd-bus/kdbus.h +++ b/src/libsystemd-bus/kdbus.h @@ -237,7 +237,7 @@ enum { /* Items to append to struct kdbus_cmd_hello */ enum { KDBUS_HELLO_NULL, - KDBUS_HELLO_BUFFER, /* kdbus_vec, userspace supplied buffer to + KDBUS_HELLO_POOL, /* kdbus_vec, userspace supplied buffer to * place received messages */ }; diff --git a/src/libsystemd-bus/test-bus-memfd.c b/src/libsystemd-bus/test-bus-memfd.c index 4b22ea9a68..37e150a397 100644 --- a/src/libsystemd-bus/test-bus-memfd.c +++ b/src/libsystemd-bus/test-bus-memfd.c @@ -40,32 +40,22 @@ int main(int argc, char *argv[]) { if (r == -ENOENT) return EXIT_TEST_SKIP; - r = sd_memfd_map(m, 0, 6, (void**) &s); + r = sd_memfd_map(m, 0, 12, (void**) &s); assert_se(r >= 0); - strcpy(s, "hallo"); + strcpy(s, "----- world"); r = sd_memfd_set_sealed(m, 1); assert_se(r == -EPERM); assert_se(write(sd_memfd_get_fd(m), "he", 2) == 2); - assert_se(write(sd_memfd_get_fd(m), "HE", 2) == 2); - - log_error("lseek = %llu", (unsigned long long) lseek(sd_memfd_get_fd(m), 0, SEEK_CUR)); - - log_info("<%s>", s); - - access("HUHU", F_OK); + assert_se(write(sd_memfd_get_fd(m), "ll", 2) == 2); assert_se(sd_memfd_get_file(m, &f) >= 0); - fputc('L', f); + fputc('o', f); fflush(f); - access("HAHA", F_OK); - - log_info("<%s>", s); - - assert_se(munmap(s, 6) == 0); + assert_se(munmap(s, 12) == 0); r = sd_memfd_get_sealed(m); assert_se(r == 0); @@ -74,7 +64,7 @@ int main(int argc, char *argv[]) { assert_se(r >= 0); assert_se(sz = page_size()); - r = sd_memfd_set_size(m, 6); + r = sd_memfd_set_size(m, 12); assert_se(r >= 0); r = sd_memfd_set_sealed(m, 1); @@ -93,9 +83,9 @@ int main(int argc, char *argv[]) { r = sd_memfd_get_size(m, &sz); assert_se(r >= 0); - assert_se(sz = 6); + assert_se(sz = 12); - r = sd_memfd_map(m, 0, 6, (void**) &s); + r = sd_memfd_map(m, 0, 12, (void**) &s); assert_se(r >= 0); r = sd_memfd_set_sealed(m, 1); @@ -104,10 +94,8 @@ int main(int argc, char *argv[]) { r = sd_memfd_set_sealed(m, 0); assert_se(r == -EPERM); - log_info("<%s>", s); - - assert_se(streq(s, "heLlo")); - assert_se(munmap(s, 6) == 0); + assert_se(streq(s, "hello world")); + assert_se(munmap(s, 12) == 0); r = sd_memfd_set_sealed(m, 0); assert_se(r >= 0); -- cgit v1.2.3-54-g00ecf