[asterisk-commits] tilghman: trunk r233358 - in /trunk: include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Dec 6 01:01:13 CST 2009
Author: tilghman
Date: Sun Dec 6 01:01:06 2009
New Revision: 233358
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=233358
Log:
Move implementation of closefrom(3) from app.c to strcompat.c
Modified:
trunk/include/asterisk/compat.h
trunk/main/app.c
trunk/main/strcompat.c
Modified: trunk/include/asterisk/compat.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/compat.h?view=diff&rev=233358&r1=233357&r2=233358
==============================================================================
--- trunk/include/asterisk/compat.h (original)
+++ trunk/include/asterisk/compat.h Sun Dec 6 01:01:06 2009
@@ -73,6 +73,10 @@
#include "asterisk/poll-compat.h"
#endif
+#ifndef HAVE_CLOSEFROM
+void closefrom(int lowfd);
+#endif
+
#if !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC)
int __attribute__((format(printf, 2, 3))) asprintf(char **str, const char *fmt, ...);
#endif
Modified: trunk/main/app.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/app.c?view=diff&rev=233358&r1=233357&r2=233358
==============================================================================
--- trunk/main/app.c (original)
+++ trunk/main/app.c Sun Dec 6 01:01:06 2009
@@ -33,8 +33,6 @@
#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) */
#ifdef HAVE_CAP
#include <sys/capability.h>
@@ -2008,24 +2006,7 @@
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 < rl.rlim_cur; 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. */
- while (dup2(null, x) < 0 && errno == EINTR);
- close(x);
- }
- }
- close(null);
-#endif
}
int ast_safe_fork(int stop_reaper)
Modified: trunk/main/strcompat.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/strcompat.c?view=diff&rev=233358&r1=233357&r2=233358
==============================================================================
--- trunk/main/strcompat.c (original)
+++ trunk/main/strcompat.c Sun Dec 6 01:01:06 2009
@@ -22,6 +22,10 @@
#include "asterisk.h"
#include <ctype.h>
+#include <sys/time.h> /* for getrlimit(2) */
+#include <sys/resource.h> /* for getrlimit(2) */
+#include <sys/types.h> /* for opendir(3) */
+#include <dirent.h> /* for opendir(3) */
#ifndef HAVE_STRSEP
char *strsep(char **str, const char *delims)
@@ -399,3 +403,33 @@
}
#endif
+#ifndef HAVE_CLOSEFROM
+void closefrom(int n)
+{
+ long x;
+ struct rlimit rl;
+ DIR *dir;
+ char path[16], *result;
+ struct dirent *entry;
+
+ snprintf(path, sizeof(path), "/proc/%d/fd", (int) getpid());
+ if ((dir = opendir(path))) {
+ while ((entry = readdir(dir))) {
+ /* Skip . and .. */
+ if (entry->d_name[0] == '.') {
+ continue;
+ }
+ if ((x = strtol(entry->d_name, &result, 10)) && x >= n) {
+ close(x);
+ }
+ }
+ closedir(dir);
+ } else {
+ getrlimit(RLIMIT_NOFILE, &rl);
+ for (x = n; x < rl.rlim_cur; x++) {
+ close(x);
+ }
+ }
+}
+#endif
+
More information about the asterisk-commits
mailing list