vfs: Convert vfswrap_fs_capabilities to synthetic_smb_fname
[Samba/gebeck_regimport.git] / lib / ccan / failtest / test / run-with-fdlimit.c
blob6b4483f07eea7a41a79423963318c7e6489ce73d
1 /* Include the C files directly. */
2 #include <ccan/failtest/failtest.c>
3 #include <stdlib.h>
4 #include <err.h>
5 #include <ccan/tap/tap.h>
7 int main(void)
9 int fd, pfd[2], ecode;
10 struct rlimit lim;
12 if (getrlimit(RLIMIT_NOFILE, &lim) != 0)
13 err(1, "getrlimit RLIMIT_NOFILE fail?");
15 printf("rlimit = %lu/%lu (inf=%lu)\n",
16 (long)lim.rlim_cur, (long)lim.rlim_max,
17 (long)RLIM_INFINITY);
18 lim.rlim_cur /= 2;
19 if (lim.rlim_cur < 8)
20 errx(1, "getrlimit limit %li too low", (long)lim.rlim_cur);
21 if (setrlimit(RLIMIT_NOFILE, &lim) != 0)
22 err(1, "setrlimit RLIMIT_NOFILE (%li/%li)",
23 (long)lim.rlim_cur, (long)lim.rlim_max);
25 plan_tests(2);
26 failtest_init(0, NULL);
28 if (pipe(pfd))
29 abort();
31 fd = failtest_open("run-with-fdlimit-scratch", "run-with_fdlimit.c", 1,
32 O_RDWR|O_CREAT, 0600);
33 if (fd == -1) {
34 /* We are the child: write error code for parent to check. */
35 ecode = errno;
36 if (write(pfd[1], &ecode, sizeof(ecode)) != sizeof(ecode))
37 abort();
38 failtest_exit(0);
41 /* Check child got correct errno. */
42 ok1(read(pfd[0], &ecode, sizeof(ecode)) == sizeof(ecode));
43 ok1(ecode == EACCES);
45 /* Clean up. */
46 failtest_close(fd, "run-open.c", 1);
47 close(pfd[0]);
48 close(pfd[1]);
50 return exit_status();