[LTP] [PATCH v4 2/4] syscalls: lchown01: Convert to new API
Cyril Hrubis
chrubis@suse.cz
Thu Aug 28 13:28:37 CEST 2025
Hi!
> -struct test_case_t {
> +static struct test_case_t {
> char *desc;
> uid_t user_id;
> gid_t group_id;
> +} test_cases[] = {
> + { "Change Owner/Group ids", 700, 701 },
> + { "Change Owner id only", 702, 0 },
> + { "Change Owner/Group ids", 703, 701 },
> + { "Change Group id only", 0, 704 },
> + { "Change Group/Group ids", 703, 705 },
> + { "Change none", 0, 0 },
> };
>
> -static struct test_case_t test_cases[] = {
> - {"Change Owner/Group ids", 700, 701},
> - {"Change Owner id only", 702, -1},
> - {"Change Owner/Group ids", 703, 701},
> - {"Change Group id only", -1, 704},
> - {"Change Group/Group ids", 703, 705},
> - {"Change none", -1, -1},
> - {NULL, 0, 0}
> -};
This actually changes what the test does. To cite manual page:
"If the owner or group is specified as -1, then that ID is not changed."
The -1 values there were correct, all we need to do in case we have -1
in there is to lstat() the file before lchonw() and use that value for
the check.
> - cleanup();
> - tst_exit();
> + struct test_case_t *tc = &test_cases[i];
> + uid_t user_id = tc->user_id;
> + gid_t group_id = tc->group_id;
> +
> + tst_res(TINFO, "%s", tc->desc);
> + SAFE_LCHOWN(SFILE, user_id, group_id);
> + SAFE_LSTAT(SFILE, &stat_buf);
> + TST_EXP_EQ_LI(stat_buf.st_uid, user_id);
> + TST_EXP_EQ_LI(stat_buf.st_gid, group_id);
So this would look like:
uid_t usr_id = tc->user_id;
gid_t grp_id = tc->group_id;
SAFE_LSTAT(SFILE, &stat_buf);
uid_t cmp_usr_id = usr_id == -1 ? stat_buf.st_uid : usr_id;
uid_t cmp_grp_id = grp_id == -1 ? stat_buf.st_gid : grp_id;
SAFE_LCHOWN(SFILE, user_id, group_id);
SAFE_LSTAT(SFILE, &stat_buf);
TST_EXP_EQ_LI(stat_buf.st_uid, cmp_user_id);
TST_EXP_EQ_LI(stat_buf.st_gid, cmp_group_id);
And this is exactly what the code was done before.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list