diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-01-12 23:06:12 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-01-12 23:06:12 +0000 |
commit | c0765c5fbf583f6cd61d72e1f8cd4c985059888f (patch) | |
tree | 653bff8fd1cd0a6a58455c6156638d07bac2ad95 /main | |
parent | 67837440f9c41169fd3ca5ac47f6729004b03003 (diff) |
Some platforms (notably, the BSDs) have a more efficient implementation called
closefrom(3).
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@168522 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/app.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/main/app.c b/main/app.c index d3d3b3784..bda021d56 100644 --- a/main/app.c +++ b/main/app.c @@ -33,6 +33,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include <regex.h> #include <sys/file.h> /* added this to allow to compile, sorry! */ #include <signal.h> +#include <sys/time.h> /* for getrlimit(2) */ +#include <sys/resource.h> /* for getrlimit(2) */ +#include <stdlib.h> /* for closefrom(3) */ #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */ #include "asterisk/channel.h" @@ -1839,18 +1842,24 @@ int ast_get_encoded_str(const char *stream, char *result, size_t result_size) void ast_close_fds_above_n(int n) { +#ifdef HAVE_CLOSEFROM + closefrom(n + 1); +#else int x, null; + struct rlimit rl; + getrlimit(RLIMIT_NOFILE, &rl); null = open("/dev/null", O_RDONLY); - for (x = n + 1; x <= (null >= 8192 ? null : 8192); x++) { + for (x = n + 1; x < rl.rlim_max; x++) { if (x != null) { /* Side effect of dup2 is that it closes any existing fd without error. * This prevents valgrind and other debugging tools from sending up * false error reports. */ - dup2(null, x); + while (dup2(null, x) < 0 && errno == EINTR); close(x); } } close(null); +#endif } int ast_safe_fork(int stop_reaper) |