summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-05-10 17:33:44 +0200
committerLennart Poettering <lennart@poettering.net>2013-05-10 17:34:14 +0200
commita7c54c8c1fc4101e784c101e680975f2143381ce (patch)
tree5e099806f62b4fa5f5a670970e632ccf6b7ccf37 /src/libsystemd-bus
parentc2384970ff604e6341879bc965305b84533cdebf (diff)
bus: extend memfd test
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r--src/libsystemd-bus/sd-memfd.c2
-rw-r--r--src/libsystemd-bus/test-bus-memfd.c47
2 files changed, 41 insertions, 8 deletions
diff --git a/src/libsystemd-bus/sd-memfd.c b/src/libsystemd-bus/sd-memfd.c
index 51b111e8b5..98a8e0893a 100644
--- a/src/libsystemd-bus/sd-memfd.c
+++ b/src/libsystemd-bus/sd-memfd.c
@@ -106,7 +106,7 @@ int sd_memfd_get_file(sd_memfd *m, FILE **f) {
if (!f)
return -EINVAL;
- if (!m->fd) {
+ if (!m->f) {
m->f = fdopen(m->fd, "r+");
if (!m->f)
return -errno;
diff --git a/src/libsystemd-bus/test-bus-memfd.c b/src/libsystemd-bus/test-bus-memfd.c
index 4c5ae21a8c..4b22ea9a68 100644
--- a/src/libsystemd-bus/test-bus-memfd.c
+++ b/src/libsystemd-bus/test-bus-memfd.c
@@ -32,6 +32,7 @@ int main(int argc, char *argv[]) {
char *s;
uint64_t sz;
int r, fd;
+ FILE *f;
log_set_max_level(LOG_DEBUG);
@@ -43,18 +44,31 @@ int main(int argc, char *argv[]) {
assert_se(r >= 0);
strcpy(s, "hallo");
- assert_se(munmap(s, 6) == 0);
+
+ 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);
- r = sd_memfd_get_sealed(m);
- assert_se(r == 0);
+ log_error("lseek = %llu", (unsigned long long) lseek(sd_memfd_get_fd(m), 0, SEEK_CUR));
- r = sd_memfd_set_sealed(m, 1);
- assert_se(r >= 0);
+ log_info("<%s>", s);
+
+ access("HUHU", F_OK);
+
+ assert_se(sd_memfd_get_file(m, &f) >= 0);
+ fputc('L', f);
+ fflush(f);
+
+ access("HAHA", F_OK);
+
+ log_info("<%s>", s);
+
+ assert_se(munmap(s, 6) == 0);
r = sd_memfd_get_sealed(m);
- assert_se(r == 1);
+ assert_se(r == 0);
r = sd_memfd_get_size(m, &sz);
assert_se(r >= 0);
@@ -63,6 +77,12 @@ int main(int argc, char *argv[]) {
r = sd_memfd_set_size(m, 6);
assert_se(r >= 0);
+ r = sd_memfd_set_sealed(m, 1);
+ assert_se(r >= 0);
+
+ r = sd_memfd_get_sealed(m);
+ assert_se(r == 1);
+
fd = sd_memfd_dup_fd(m);
assert_se(fd >= 0);
@@ -78,8 +98,21 @@ int main(int argc, char *argv[]) {
r = sd_memfd_map(m, 0, 6, (void**) &s);
assert_se(r >= 0);
- assert_se(streq(s, "hello"));
+ r = sd_memfd_set_sealed(m, 1);
+ assert_se(r == -EALREADY);
+
+ 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);
+ r = sd_memfd_set_sealed(m, 0);
+ assert_se(r >= 0);
+
+ sd_memfd_free(m);
+
return 0;
}