1 #define _LARGEFILE_SOURCE
2 #define _LARGEFILE64_SOURCE
8 #include <sys/resource.h>
12 int main(int argc
, char **argv
)
14 struct rlimit64 oldrlim
;
15 struct rlimit64 newrlim
;
20 if (getrlimit64(RLIMIT_NOFILE
, &oldrlim
) < 0)
26 newrlim
.rlim_cur
= oldrlim
.rlim_max
+1;
27 newrlim
.rlim_max
= oldrlim
.rlim_max
;
28 if (setrlimit64(RLIMIT_NOFILE
, &newrlim
) == -1)
30 if (errno
!= EINVAL
) {
31 fprintf(stderr
, "setrlimit64 exceeding hardlimit must set errno=EINVAL\n");
37 fprintf(stderr
, "setrlimit64 exceeding hardlimit must return -1\n");
41 newrlim
.rlim_cur
= oldrlim
.rlim_max
;
42 newrlim
.rlim_max
= oldrlim
.rlim_max
+1;
43 if (setrlimit64(RLIMIT_NOFILE
, &newrlim
) == -1)
46 fprintf(stderr
, "setrlimit64 changing hardlimit must set errno=EPERM\n");
52 fprintf(stderr
, "setrlimit64 changing hardlimit must return -1\n");
56 newrlim
.rlim_cur
= oldrlim
.rlim_cur
/ 2;
57 newrlim
.rlim_max
= oldrlim
.rlim_max
;
59 if (setrlimit64(RLIMIT_NOFILE
, &newrlim
) < 0)
61 perror("setrlimit64");
65 if (getrlimit64(RLIMIT_NOFILE
, &newrlim
) < 0)
71 if (newrlim
.rlim_cur
!= oldrlim
.rlim_cur
/ 2)
73 fprintf(stderr
, "rlim_cur is %llu (should be %llu)\n",
74 (unsigned long long)newrlim
.rlim_cur
,
75 (unsigned long long)oldrlim
.rlim_cur
/ 2);
78 if (newrlim
.rlim_max
!= oldrlim
.rlim_max
)
80 fprintf(stderr
, "rlim_max is %llu (should be %llu)\n",
81 (unsigned long long)newrlim
.rlim_max
,
82 (unsigned long long)oldrlim
.rlim_max
);
85 newrlim
.rlim_cur
-= 3; /* allow for stdin, stdout and stderr */
87 while (newrlim
.rlim_cur
-- > 0)
89 if (open("/dev/null", O_RDONLY
) < 0)
95 if ((fd
= open("/dev/null", O_RDONLY
)) >= 0)
97 fprintf(stderr
, "open succeeded with fd %d - it should have failed!\n", fd
);
99 else if (errno
!= EMFILE
)