[LTP] [PATCH v2] unshare03: set nr_open with sizeof(long)*8
lufei
lufei@uniontech.com
Wed Apr 9 09:49:06 CEST 2025
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
More information about the ltp
mailing list