diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-10-06 16:31:49 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-10-07 11:49:22 +0200 |
commit | c53e07e249d4635babe901fd40dc1ecdfc32f0d4 (patch) | |
tree | a0ea4c9b2d302ddfe19a83e71ebe680a0055f102 /src/test/test-xattr-util.c | |
parent | c9d1c37c93b779006d901b13e1c32b79cd03877a (diff) | |
download | systemd-c53e07e249d4635babe901fd40dc1ecdfc32f0d4.tar.gz |
xattr-util: merge various getxattr()/listxattr() helpers into getxattr_at_malloc() + listxattr_at_malloc()
Unfortunately fgetxattr() and flistxattr() don't work via O_PATH fds.
Let's thus add fallbacks to go via /proc/self/fd/ in these cases.
Also, let's merge all the various flavours we have here into singular
implementations that can do everything we need:
1. malloc() loop handling
2. by fd, by path, or combination (i.e. a proper openat() like API)
3. work on O_PATH
Diffstat (limited to 'src/test/test-xattr-util.c')
-rw-r--r-- | src/test/test-xattr-util.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/test/test-xattr-util.c b/src/test/test-xattr-util.c index 3fbae5738f..b30a639ff3 100644 --- a/src/test/test-xattr-util.c +++ b/src/test/test-xattr-util.c @@ -15,14 +15,12 @@ #include "tmpfile-util.h" #include "xattr-util.h" -static void test_fgetxattrat_fake(void) { +static void test_getxattr_at_malloc(void) { char t[] = "/var/tmp/xattrtestXXXXXX"; _cleanup_free_ char *value = NULL; _cleanup_close_ int fd = -1; const char *x; - char v[3]; int r; - size_t size; log_info("/* %s */", __func__); @@ -38,21 +36,24 @@ static void test_fgetxattrat_fake(void) { fd = open(t, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY); assert_se(fd >= 0); - assert_se(fgetxattrat_fake(fd, "test", "user.foo", v, 3, 0, &size) >= 0); - assert_se(size == 3); - assert_se(memcmp(v, "bar", 3) == 0); + assert_se(getxattr_at_malloc(fd, "test", "user.foo", 0, &value) == 3); + assert_se(memcmp(value, "bar", 3) == 0); + value = mfree(value); + + assert_se(getxattr_at_malloc(AT_FDCWD, x, "user.foo", 0, &value) == 3); + assert_se(memcmp(value, "bar", 3) == 0); + value = mfree(value); safe_close(fd); fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY); assert_se(fd >= 0); - r = fgetxattrat_fake(fd, "usr", "user.idontexist", v, 3, 0, &size); + r = getxattr_at_malloc(fd, "usr", "user.idontexist", 0, &value); assert_se(r == -ENODATA || ERRNO_IS_NOT_SUPPORTED(r)); safe_close(fd); fd = open(x, O_PATH|O_CLOEXEC); assert_se(fd >= 0); - r = fgetxattrat_fake_malloc(fd, NULL, "user.foo", AT_EMPTY_PATH, &value); - assert_se(r == 3); + assert_se(getxattr_at_malloc(fd, NULL, "user.foo", 0, &value) == 3); assert_se(streq(value, "bar")); cleanup: @@ -68,7 +69,7 @@ static void test_getcrtime(void) { log_info("/* %s */", __func__); - assert_se(tmp_dir(&vt) >= 0); + assert_se(var_tmp_dir(&vt) >= 0); fd = open_tmpfile_unlinkable(vt, O_RDWR); assert_se(fd >= 0); @@ -92,7 +93,7 @@ static void test_getcrtime(void) { int main(void) { test_setup_logging(LOG_DEBUG); - test_fgetxattrat_fake(); + test_getxattr_at_malloc(); test_getcrtime(); return 0; |