From: Tobias Brunner Date: Thu, 13 Oct 2011 08:34:51 +0000 (+0200) Subject: Added a replacement for closefrom (available on *BSD). X-Git-Tag: 4.6.0~215 X-Git-Url: https://git.strongswan.org/?p=strongswan.git;a=commitdiff_plain;h=9a8fdc159a49ba82568f53cb9275b3ded092ba76 Added a replacement for closefrom (available on *BSD). --- diff --git a/configure.in b/configure.in index 99cec7c..c8aa68a 100644 --- a/configure.in +++ b/configure.in @@ -375,7 +375,7 @@ dnl check if native rwlocks are available AC_CHECK_FUNCS(pthread_rwlock_init) LIBS=$saved_LIBS -AC_CHECK_FUNCS(prctl mallinfo getpass) +AC_CHECK_FUNCS(prctl mallinfo getpass closefrom) AC_CHECK_HEADERS(sys/sockio.h glob.h) AC_CHECK_HEADERS(net/pfkeyv2.h netipsec/ipsec.h netinet6/ipsec.h linux/udp.h) diff --git a/src/libstrongswan/utils.c b/src/libstrongswan/utils.c index 1129ea3..eca613a 100644 --- a/src/libstrongswan/utils.c +++ b/src/libstrongswan/utils.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2010 Tobias Brunner + * Copyright (C) 2008-2011 Tobias Brunner * Copyright (C) 2005-2008 Martin Willi * Hochschule fuer Technik Rapperswil * @@ -193,6 +193,25 @@ bool mkdir_p(const char *path, mode_t mode) return TRUE; } +#ifndef HAVE_CLOSEFROM +/** + * Described in header. + */ +void closefrom(int lowfd) +{ + int maxfd, fd; + maxfd = (int)sysconf(_SC_OPEN_MAX); + if (maxfd < 0) + { + maxfd = 256; + } + for (fd = lowfd; fd < maxfd; fd++) + { + close(fd); + } +} +#endif /* HAVE_CLOSEFROM */ + /** * Return monotonic time */ diff --git a/src/libstrongswan/utils.h b/src/libstrongswan/utils.h index f04c633..0f06fec 100644 --- a/src/libstrongswan/utils.h +++ b/src/libstrongswan/utils.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2010 Tobias Brunner + * Copyright (C) 2008-2011 Tobias Brunner * Copyright (C) 2008 Martin Willi * Hochschule fuer Technik Rapperswil * @@ -408,6 +408,15 @@ char *translate(char *str, const char *from, const char *to); */ bool mkdir_p(const char *path, mode_t mode); +#ifndef HAVE_CLOSEFROM +/** + * Close open file descriptors greater than or equal to lowfd. + * + * @param lowfd start closing file descriptoros from here + */ +void closefrom(int lowfd); +#endif + /** * Get a timestamp from a monotonic time source. *