File tree Expand file tree Collapse file tree 2 files changed +42
-3
lines changed
test/jdk/java/lang/ProcessBuilder/FDLeakTest Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change 2727 * @summary Check that we don't leak FDs
2828 * @requires os.family != "windows"
2929 * @library /test/lib
30- * @run main/othervm/native/timeout=480 -Djdk.lang.Process.launchMechanism=posix_spawn -agentlib:FDLeaker FDLeakTest
30+ * @run main/othervm/native -Djdk.lang.Process.launchMechanism=posix_spawn -agentlib:FDLeaker FDLeakTest
3131 */
3232
3333/**
3434 * @test id=fork
3535 * @summary Check that we don't leak FDs
3636 * @requires os.family != "windows"
3737 * @library /test/lib
38- * @run main/othervm/native/timeout=480 -Djdk.lang.Process.launchMechanism=fork -agentlib:FDLeaker FDLeakTest
38+ * @run main/othervm/native -Djdk.lang.Process.launchMechanism=fork -agentlib:FDLeaker FDLeakTest
3939 */
4040
4141/**
4242 * @test id=vfork
4343 * @summary Check that we don't leak FDs
4444 * @requires os.family == "linux"
4545 * @library /test/lib
46- * @run main/othervm/native/timeout=480 -Djdk.lang.Process.launchMechanism=vfork -agentlib:FDLeaker FDLeakTest
46+ * @run main/othervm/native -Djdk.lang.Process.launchMechanism=vfork -agentlib:FDLeaker FDLeakTest
4747 */
4848
4949import jdk .test .lib .process .ProcessTools ;
Original file line number Diff line number Diff line change 2121 * questions.
2222 */
2323
24+ #include <errno.h>
2425#include <stdio.h>
26+ #include <stdlib.h>
27+ #include <string.h>
28+ #include <sys/resource.h>
2529#include "jvmti.h"
2630
31+ static jint limit_num_fds ();
32+
2733JNIEXPORT jint JNICALL
2834Agent_OnLoad (JavaVM * jvm , char * options , void * reserved ) {
35+ // Lower the number of possible open files to make the test go faster
36+ jint ret = limit_num_fds ();
37+ if (ret != 0 ) {
38+ fprintf (stderr , "Failed to limit number of fds: %s" , strerror (errno ));
39+ return ret ;
40+ }
41+
2942 const char * filename = "./testfile_FDLeaker.txt" ;
3043 FILE * f = fopen (filename , "w" );
3144 if (f == NULL ) {
45+ fprintf (stderr , "Failed to open file: %s" , strerror (errno ));
3246 return JNI_ERR ;
3347 }
48+
3449 printf ("Opened and leaked %s (%d)" , filename , fileno (f ));
3550 return JNI_OK ;
3651}
52+
53+ static jint limit_num_fds () {
54+ struct rlimit rl ;
55+
56+ // Fetch the current limit
57+ int ret = getrlimit (RLIMIT_NOFILE , & rl );
58+ if (ret != 0 ) {
59+ return JNI_ERR ;
60+ }
61+
62+ // Use a lower value unless it is already low
63+ rlim_t limit = 100 ;
64+ if (limit < rl .rlim_cur ) {
65+ rl .rlim_cur = limit ;
66+ }
67+
68+ // Lower the value
69+ int ret2 = setrlimit (RLIMIT_NOFILE , & rl );
70+ if (ret2 != 0 ) {
71+ return JNI_ERR ;
72+ }
73+
74+ return JNI_OK ;
75+ }
You can’t perform that action at this time.
0 commit comments