mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-01 11:32:25 +00:00
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
This commit is contained in:
13
main/app.c
13
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)
|
||||
|
||||
Reference in New Issue
Block a user