From: Cyril Hrubis <chrubis@suse.cz>
To: "Ricardo B. Marlière" <rbm@suse.com>
Cc: Linux Test Project <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v4 2/4] syscalls: lchown01: Convert to new API
Date: Thu, 28 Aug 2025 13:28:37 +0200 [thread overview]
Message-ID: <aLA9ZbNA8erKn7Qh@yuki.lan> (raw)
In-Reply-To: <20250828-conversions-lchown-v4-2-60dd9a0145f3@suse.com>
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-08-28 11:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-28 10:23 [LTP] [PATCH v4 0/4] syscalls: lchown: Convert to new API Ricardo B. Marlière via ltp
2025-08-28 10:23 ` [LTP] [PATCH v4 1/4] lib: Add SAFE_LCHOWN Ricardo B. Marlière via ltp
2025-08-28 11:15 ` Cyril Hrubis
2025-08-28 10:23 ` [LTP] [PATCH v4 2/4] syscalls: lchown01: Convert to new API Ricardo B. Marlière via ltp
2025-08-28 11:28 ` Cyril Hrubis [this message]
2025-08-29 20:59 ` Ricardo B. Marlière via ltp
2025-08-28 10:23 ` [LTP] [PATCH v4 3/4] syscalls: lchown02: " Ricardo B. Marlière via ltp
2025-08-28 11:45 ` Cyril Hrubis
2025-08-28 10:23 ` [LTP] [PATCH v4 4/4] syscalls: lchown03: Merge into lchown02 Ricardo B. Marlière via ltp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aLA9ZbNA8erKn7Qh@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=rbm@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.