public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: lufei <lufei@uniontech.com>
To: ltp@lists.linux.it
Cc: lufei <lufei@uniontech.com>, viro@zeniv.linux.org.uk
Subject: [LTP] [PATCH v2] unshare03: set nr_open with sizeof(long)*8
Date: Wed,  9 Apr 2025 15:49:06 +0800	[thread overview]
Message-ID: <20250409074906.128290-1-lufei@uniontech.com> (raw)
In-Reply-To: <20250314044257.1673303-1-lufei@uniontech.com>

Set nr_open with sizeof(long)*8 to trigger EMFILE, instead of reading
number of filedescriptors limit.

Signed-off-by: lufei <lufei@uniontech.com>
---
 testcases/kernel/syscalls/unshare/unshare03.c | 23 ++-----------------
 1 file changed, 2 insertions(+), 21 deletions(-)

diff --git a/testcases/kernel/syscalls/unshare/unshare03.c b/testcases/kernel/syscalls/unshare/unshare03.c
index 7c5e71c4e..c3b98930d 100644
--- a/testcases/kernel/syscalls/unshare/unshare03.c
+++ b/testcases/kernel/syscalls/unshare/unshare03.c
@@ -17,44 +17,25 @@
 #include "lapi/sched.h"
 
 #define FS_NR_OPEN "/proc/sys/fs/nr_open"
-#define NR_OPEN_LIMIT 1024
-#define NR_OPEN_DUP 64
 
 #ifdef HAVE_UNSHARE
 
 static void run(void)
 {
-	int nr_open;
-	int nr_limit;
-	struct rlimit rlimit;
 	struct tst_clone_args args = {
 		.flags = CLONE_FILES,
 		.exit_signal = SIGCHLD,
 	};
 
-	SAFE_FILE_SCANF(FS_NR_OPEN, "%d", &nr_open);
-	tst_res(TDEBUG, "Maximum number of file descriptors: %d", nr_open);
+	int nr_open = sizeof(long) * 8;
 
-	nr_limit = nr_open + NR_OPEN_LIMIT;
-	SAFE_FILE_PRINTF(FS_NR_OPEN, "%d", nr_limit);
-
-	SAFE_GETRLIMIT(RLIMIT_NOFILE, &rlimit);
-
-	rlimit.rlim_cur = nr_limit;
-	rlimit.rlim_max = nr_limit;
-
-	SAFE_SETRLIMIT(RLIMIT_NOFILE, &rlimit);
-	tst_res(TDEBUG, "Set new maximum number of file descriptors to : %d",
-		nr_limit);
-
-	SAFE_DUP2(2, nr_open + NR_OPEN_DUP);
+	SAFE_DUP2(2, nr_open + 1);
 
 	if (!SAFE_CLONE(&args)) {
 		SAFE_FILE_PRINTF(FS_NR_OPEN, "%d", nr_open);
 		TST_EXP_FAIL(unshare(CLONE_FILES), EMFILE);
 		exit(0);
 	}
-
 }
 
 static void setup(void)
-- 
2.39.3


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

  parent reply	other threads:[~2025-04-09  7:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14  4:42 [LTP] [PATCH] unshare03: using soft limit of NOFILE lufei
2025-03-27 10:33 ` Petr Vorel
     [not found]   ` <0A99FFBB46DDB0B4+Z+YKSlAwn1vx3Dz4@rocky>
2025-03-28  8:50     ` Petr Vorel
2025-04-01 10:11 ` Cyril Hrubis
2025-04-01 12:54   ` Petr Vorel
2025-04-01 13:55     ` Cyril Hrubis
2025-04-09  6:41   ` Lu Fei
2025-04-09  7:49 ` lufei [this message]
2025-04-10 15:35   ` [LTP] [PATCH v2] unshare03: set nr_open with sizeof(long)*8 Jan Stancek via ltp
2025-04-11  3:09   ` Li Wang via ltp
2025-04-11  3:21     ` Li Wang via ltp
2025-04-11  6:01       ` Lu Fei
2025-04-11  9:03         ` Cyril Hrubis
2025-04-11  9:30   ` [LTP] [PATCH v3] " lufei
2025-04-16  1:55     ` Li Wang 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=20250409074906.128290-1-lufei@uniontech.com \
    --to=lufei@uniontech.com \
    --cc=ltp@lists.linux.it \
    --cc=viro@zeniv.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox