All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Xu <xuyang2018.jy@fujitsu.com>
To: <ltp@lists.linux.it>
Subject: [LTP] [PATCH v1 1/3] syscalls/dup202: Also check mode whethter change when calling chmod after dup2
Date: Wed, 22 Sep 2021 13:39:40 +0800	[thread overview]
Message-ID: <1632289182-2191-1-git-send-email-xuyang2018.jy@fujitsu.com> (raw)

Since the two file descriptors refer to the same open file description, they should
share the file status. So change mode for file after creat, then check whether oldfd
mode equals newfd mode.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/dup2/dup202.c | 30 +++++++++++++++++++------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/dup2/dup202.c b/testcases/kernel/syscalls/dup2/dup202.c
index 94bedcf18..c50b56ba0 100644
--- a/testcases/kernel/syscalls/dup2/dup202.c
+++ b/testcases/kernel/syscalls/dup2/dup202.c
@@ -8,10 +8,14 @@
  * [Description]
  *
  * Test whether the access mode are the same for both file descriptors.
+ * Style: creat mode, dup2, [change mode], check mode
  *
- * - 0: read only ? "0444"
- * - 1: write only ? "0222"
- * - 2: read/write ? "0666"
+ * - 0: read only, dup2, null, read only ? "0444"
+ * - 1: write only, dup2, null, write only ? "0222"
+ * - 2: read/write, dup2, null, read/write ? "0666"
+ * - 3: read/write/execute, dup2, read only, read only ? "0444"
+ * - 4: read/write/execute, dup2, write only, write only ? "0222"
+ * - 5: read/write/execute, dup2, read/write, read/write ? "0666"
  */
 
 #include <errno.h>
@@ -29,10 +33,15 @@ static int duprdo = 10, dupwro = 20, duprdwr = 30;
 static struct tcase {
 	int *nfd;
 	mode_t mode;
+	/* 0 - set mode before dup2, 1 - change mode after dup2 */
+	int flag;
 } tcases[] = {
-	{&duprdo, 0444},
-	{&dupwro, 0222},
-	{&duprdwr, 0666},
+	{&duprdo, 0444, 0},
+	{&dupwro, 0222, 0},
+	{&duprdwr, 0666, 0},
+	{&duprdo, 0444, 1},
+	{&dupwro, 0222, 1},
+	{&duprdwr, 0666, 1},
 };
 
 static void setup(void)
@@ -52,7 +61,10 @@ static void run(unsigned int i)
 	struct stat oldbuf, newbuf;
 	struct tcase *tc = tcases + i;
 
-	ofd = SAFE_CREAT(testfile, tc->mode);
+	if (tc->flag)
+		ofd = SAFE_CREAT(testfile, 0777);
+	else
+		ofd = SAFE_CREAT(testfile, tc->mode);
 	nfd = *tc->nfd;
 
 	TEST(dup2(ofd, nfd));
@@ -60,6 +72,10 @@ static void run(unsigned int i)
 		tst_res(TFAIL | TTERRNO, "call failed unexpectedly");
 		goto free;
 	}
+	if (tc->flag) {
+		SAFE_CHMOD(testfile, tc->mode);
+		tst_res(TINFO, "original mode 0777, new mode 0%o after chmod", tc->mode);
+	}
 
 	SAFE_FSTAT(ofd, &oldbuf);
 
-- 
2.23.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2021-09-22  5:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22  5:39 Yang Xu [this message]
2021-09-22  5:39 ` [LTP] [PATCH v1 2/3] syscalls/dup206: Add a test when newfd equals oldfd Yang Xu
2021-10-07 13:15   ` Cyril Hrubis
2021-09-22  5:39 ` [LTP] [PATCH v1 3/3] syscalls/dup207: Add file offset check test Yang Xu
2021-10-07 13:36   ` Cyril Hrubis
2021-10-07 12:53 ` [LTP] [PATCH v1 1/3] syscalls/dup202: Also check mode whethter change when calling chmod after dup2 Cyril Hrubis

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=1632289182-2191-1-git-send-email-xuyang2018.jy@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --cc=ltp@lists.linux.it \
    /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.