diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-03-08 14:14:22 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-03-08 06:30:48 +0100 |
commit | b442e375256d93637b38f997a78e330ba4774c43 (patch) | |
tree | b7cde6a93748b146c98410edcb5ac4c35ffffd70 /lib/ccan/failtest/failtest.c | |
parent | 256e2df9dc147b6d98afb4fa2ccdf5f65eaef30c (diff) | |
download | samba-b442e375256d93637b38f997a78e330ba4774c43.tar.gz samba-b442e375256d93637b38f997a78e330ba4774c43.tar.bz2 samba-b442e375256d93637b38f997a78e330ba4774c43.zip |
failtest: don't assume FD_SETSIZE is maximum runtime fd.
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
Diffstat (limited to 'lib/ccan/failtest/failtest.c')
-rw-r--r-- | lib/ccan/failtest/failtest.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/ccan/failtest/failtest.c b/lib/ccan/failtest/failtest.c index 701586e9b8..5f68394518 100644 --- a/lib/ccan/failtest/failtest.c +++ b/lib/ccan/failtest/failtest.c @@ -14,6 +14,7 @@ #include <sys/stat.h> #include <sys/time.h> #include <sys/mman.h> +#include <sys/resource.h> #include <signal.h> #include <assert.h> #include <ccan/time/time.h> @@ -194,11 +195,21 @@ static struct failtest_call *add_history_(enum failtest_call_type type, static int move_fd_to_high(int fd) { int i; + struct rlimit lim; + int max; - for (i = FD_SETSIZE - 1; i >= 0; i--) { + if (getrlimit(RLIMIT_NOFILE, &lim) == 0) { + max = lim.rlim_cur; + printf("Max is %i\n", max); + } else + max = FD_SETSIZE; + + for (i = max - 1; i > fd; i--) { if (fcntl(i, F_GETFL) == -1 && errno == EBADF) { - if (dup2(fd, i) == -1) - err(1, "Failed to dup fd %i to %i", fd, i); + if (dup2(fd, i) == -1) { + warn("Failed to dup fd %i to %i", fd, i); + continue; + } close(fd); return i; } |