mirror of
https://github.com/systemd/systemd.git
synced 2025-01-06 17:18:12 +03:00
test: add tests for xsetxattr()
This commit is contained in:
parent
c56c26c906
commit
d7e32d0558
@ -79,4 +79,51 @@ TEST(getcrtime) {
|
||||
}
|
||||
}
|
||||
|
||||
static void verify_xattr(int dfd, const char *expected) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
|
||||
assert_se(getxattr_at_malloc(dfd, "test", "user.foo", 0, &value) == (int) strlen(expected));
|
||||
assert_se(streq(value, expected));
|
||||
}
|
||||
|
||||
TEST(xsetxattr) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *t = NULL;
|
||||
_cleanup_close_ int dfd = -EBADF, fd = -EBADF;
|
||||
const char *x;
|
||||
int r;
|
||||
|
||||
dfd = mkdtemp_open("/var/tmp/test-xattrtestXXXXXX", O_PATH, &t);
|
||||
assert_se(dfd >= 0);
|
||||
x = strjoina(t, "/test");
|
||||
assert_se(touch(x) >= 0);
|
||||
|
||||
/* by full path */
|
||||
r = xsetxattr(AT_FDCWD, x, "user.foo", "fullpath", SIZE_MAX, 0);
|
||||
if (r < 0 && ERRNO_IS_NOT_SUPPORTED(r))
|
||||
return (void) log_tests_skipped_errno(r, "no xattrs supported on /var/tmp");
|
||||
assert_se(r >= 0);
|
||||
verify_xattr(dfd, "fullpath");
|
||||
|
||||
/* by dirfd */
|
||||
assert_se(xsetxattr(dfd, "test", "user.foo", "dirfd", SIZE_MAX, 0) >= 0);
|
||||
verify_xattr(dfd, "dirfd");
|
||||
|
||||
/* by fd (O_PATH) */
|
||||
fd = openat(dfd, "test", O_PATH|O_CLOEXEC);
|
||||
assert_se(fd >= 0);
|
||||
assert_se(xsetxattr(fd, NULL, "user.foo", "fd_opath", SIZE_MAX, 0) >= 0);
|
||||
verify_xattr(dfd, "fd_opath");
|
||||
assert_se(xsetxattr(fd, "", "user.foo", "fd_opath", SIZE_MAX, 0) == -EINVAL);
|
||||
assert_se(xsetxattr(fd, "", "user.foo", "fd_opath_empty", SIZE_MAX, AT_EMPTY_PATH) >= 0);
|
||||
verify_xattr(dfd, "fd_opath_empty");
|
||||
fd = safe_close(fd);
|
||||
|
||||
fd = openat(dfd, "test", O_RDONLY|O_CLOEXEC);
|
||||
assert_se(xsetxattr(fd, NULL, "user.foo", "fd_regular", SIZE_MAX, 0) >= 0);
|
||||
verify_xattr(dfd, "fd_regular");
|
||||
assert_se(xsetxattr(fd, "", "user.foo", "fd_regular_empty", SIZE_MAX, 0) == -EINVAL);
|
||||
assert_se(xsetxattr(fd, "", "user.foo", "fd_regular_empty", SIZE_MAX, AT_EMPTY_PATH) >= 0);
|
||||
verify_xattr(dfd, "fd_regular_empty");
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
Loading…
Reference in New Issue
Block a user