summaryrefslogtreecommitdiff
path: root/main/app.c
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2009-01-12 23:06:12 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2009-01-12 23:06:12 +0000
commitfd3cb908415b6ac1018b9ff9a78eb9105fab68df (patch)
tree653bff8fd1cd0a6a58455c6156638d07bac2ad95 /main/app.c
parenta8930194f4f07852ebc68dc0263311d567df16a7 (diff)
Some platforms (notably, the BSDs) have a more efficient implementation called
closefrom(3). git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@168522 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/app.c')
-rw-r--r--main/app.c13
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)