X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ffailtest%2Ffailtest.c;h=b3ee0337ebd96cfb7fe9a3b7cd3114fe473404c8;hb=48b700953f9c856102e91596103238f5da9ea079;hp=215ebfab360781e4592004f779c044b680148aec;hpb=a6b5111fe6948e51114c33aa34785c9fd0d403e6;p=ccan diff --git a/ccan/failtest/failtest.c b/ccan/failtest/failtest.c index 215ebfab..b3ee0337 100644 --- a/ccan/failtest/failtest.c +++ b/ccan/failtest/failtest.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -14,8 +13,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -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; } @@ -1166,6 +1177,15 @@ void *failtest_mmap(void *addr, size_t length, int prot, int flags, return p->u.mmap.ret; } +/* Since OpenBSD can't handle adding args, we use this file and line. + * This will make all mmaps look the same, reducing coverage. */ +void *failtest_mmap_noloc(void *addr, size_t length, int prot, int flags, + int fd, off_t offset) +{ + return failtest_mmap(addr, length, prot, flags, fd, offset, + __FILE__, __LINE__); +} + static void cleanup_pipe(struct pipe_call *call, bool restore) { trace("cleaning up pipe fd=%i%s,%i%s\n",