[LTP] [PATCH v5 2/2] Add listxattr04 reproducer
Petr Vorel
pvorel@suse.cz
Wed Jul 23 22:03:36 CEST 2025
Hi Andrea,
First, can you please before merge add
listxattr04 to runtest/syscalls?
With that you may add my RBT
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Thanks for the test.
3 very minor notes, up to you if you change it before merge.
> +#include <pwd.h>
I guess this is now not needed, right?
> +#include <sys/acl.h>
> +#include <sys/xattr.h>
> +
> +#define ACL_PERM "u::rw-,u:root:rwx,g::r--,o::r--,m::rwx"
> +#define TEST_FILE "test.bin"
> +
> +static acl_t acl;
> +
> +static void verify_xattr(const int size)
> +{
> + char buf[size];
> +
> + memset(buf, 0, sizeof(buf));
> +
> + if (listxattr(TEST_FILE, buf, size) == -1) {
> + if (errno != ERANGE)
> + tst_brk(TBROK | TERRNO, "listxattr() error");
> +
> + tst_res(TFAIL, "listxattr() failed to read attributes length: ERANGE");
> + return;
> + }
> +
> + tst_res(TPASS, "listxattr() correctly read attributes length");
> +}
> +
> +static void run(void)
> +{
> + int size;
> +
> + size = listxattr(TEST_FILE, NULL, 0);
> + if (size == -1)
> + tst_brk(TBROK | TERRNO, "listxattr() error");
> +
> + verify_xattr(size);
> +}
> +
> +static void setup(void)
> +{
> + int res;
> + int selinux;
> + int smack;
> +
> + selinux = tst_lsm_enabled("selinux");
> + smack = tst_lsm_enabled("smack");
> +
> + if (!selinux && !smack)
very nit: up to you, but I would avoid variables and just
if (!tst_lsm_enabled("selinux") && !tst_lsm_enabled("smack"))
tst_brk(TCONF, "There are no LSM(s) implementing xattr");
> + tst_brk(TCONF, "There are no LSM(s) implementing xattr");
> +
> + SAFE_TOUCH(TEST_FILE, 0644, NULL);
> +
> + acl = acl_from_text(ACL_PERM);
> + if (!acl)
> + tst_brk(TBROK | TERRNO, "acl_from_text() failed");
> +
> + res = acl_set_file(TEST_FILE, ACL_TYPE_ACCESS, acl);
> + if (res == -1) {
> + if (errno == EOPNOTSUPP)
> + tst_brk(TCONF | TERRNO, "acl_set_file()");
> +
> + tst_brk(TBROK | TERRNO, "acl_set_file(%s) failed", TEST_FILE);
> + }
> +}
> +
> +static void cleanup(void)
> +{
> + if (acl)
> + acl_free(acl);
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .setup = setup,
> + .cleanup = cleanup,
> + .needs_root = 1,
> + .needs_tmpdir = 1,
> + .tags = (const struct tst_tag[]) {
> + {"linux-git", "800d0b9b6a8b"},
> + {}
> + }
> +};
> +
> +#else /* HAVE_SYS_XATTR_H && HAVE_LIBACL */
> + TST_TEST_TCONF("<sys/xattr.h> or <sys/acl.h> does not exist.");
very very nit: please no dot in LTP messages.
Kind regards,
Petr
> +#endif
More information about the ltp
mailing list