mirror of
https://github.com/samba-team/samba.git
synced 2025-01-15 23:24:37 +03:00
b442e37525
This breaks when rlimit is less. Unfortunately, valgrind (32 bit x86, 3.7.0.SVN, Ubuntu) fails to set the file limit properly on the test: reducing it to the obvious getrlimit/setrlimit/getrlimit works fine, so leaving diagnostics for another day. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit a85a809bb17af6b6cf6fa31b300c6622f64ee700) Autobuild-User: Rusty Russell <rusty@rustcorp.com.au> Autobuild-Date: Thu Mar 8 06:30:48 CET 2012 on sn-devel-104
52 lines
1.2 KiB
C
52 lines
1.2 KiB
C
/* Include the C files directly. */
|
|
#include <ccan/failtest/failtest.c>
|
|
#include <stdlib.h>
|
|
#include <err.h>
|
|
#include <ccan/tap/tap.h>
|
|
|
|
int main(void)
|
|
{
|
|
int fd, pfd[2], ecode;
|
|
struct rlimit lim;
|
|
|
|
if (getrlimit(RLIMIT_NOFILE, &lim) != 0)
|
|
err(1, "getrlimit RLIMIT_NOFILE fail?");
|
|
|
|
printf("rlimit = %lu/%lu (inf=%lu)\n",
|
|
(long)lim.rlim_cur, (long)lim.rlim_max,
|
|
(long)RLIM_INFINITY);
|
|
lim.rlim_cur /= 2;
|
|
if (lim.rlim_cur < 8)
|
|
errx(1, "getrlimit limit %li too low", (long)lim.rlim_cur);
|
|
if (setrlimit(RLIMIT_NOFILE, &lim) != 0)
|
|
err(1, "setrlimit RLIMIT_NOFILE (%li/%li)",
|
|
(long)lim.rlim_cur, (long)lim.rlim_max);
|
|
|
|
plan_tests(2);
|
|
failtest_init(0, NULL);
|
|
|
|
if (pipe(pfd))
|
|
abort();
|
|
|
|
fd = failtest_open("run-with-fdlimit-scratch", "run-with_fdlimit.c", 1,
|
|
O_RDWR|O_CREAT, 0600);
|
|
if (fd == -1) {
|
|
/* We are the child: write error code for parent to check. */
|
|
ecode = errno;
|
|
if (write(pfd[1], &ecode, sizeof(ecode)) != sizeof(ecode))
|
|
abort();
|
|
failtest_exit(0);
|
|
}
|
|
|
|
/* Check child got correct errno. */
|
|
ok1(read(pfd[0], &ecode, sizeof(ecode)) == sizeof(ecode));
|
|
ok1(ecode == EACCES);
|
|
|
|
/* Clean up. */
|
|
failtest_close(fd, "run-open.c", 1);
|
|
close(pfd[0]);
|
|
close(pfd[1]);
|
|
|
|
return exit_status();
|
|
}
|