[asterisk-commits] tilghman: trunk r187302 - in /trunk: ./ agi/ build_tools/ include/ main/ utils/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 8 23:59:09 CDT 2009


Author: tilghman
Date: Wed Apr  8 23:59:05 2009
New Revision: 187302

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=187302
Log:
Merged revisions 187300-187301 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
  r187300 | tilghman | 2009-04-08 23:31:38 -0500 (Wed, 08 Apr 2009) | 3 lines
  
  Add debugging mode for diagnosing file descriptor leaks.
  (Related to issue #14625)
........
  r187301 | tilghman | 2009-04-08 23:32:40 -0500 (Wed, 08 Apr 2009) | 2 lines
  
  Oops, missed this file in the last commit.
........

Added:
    trunk/main/astfd.c
      - copied, changed from r187301, branches/1.4/main/astfd.c
Modified:
    trunk/   (props changed)
    trunk/agi/Makefile
    trunk/build_tools/cflags.xml
    trunk/include/asterisk.h
    trunk/main/Makefile
    trunk/main/asterisk.c
    trunk/main/file.c
    trunk/utils/Makefile

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/agi/Makefile
URL: http://svn.digium.com/svn-view/asterisk/trunk/agi/Makefile?view=diff&rev=187302&r1=187301&r2=187302
==============================================================================
--- trunk/agi/Makefile (original)
+++ trunk/agi/Makefile Wed Apr  8 23:59:05 2009
@@ -24,6 +24,8 @@
 endif
 
 include $(ASTTOPDIR)/Makefile.rules
+
+ASTCFLAGS+=-DSTANDALONE
 
 all: $(AGIS)
 

Modified: trunk/build_tools/cflags.xml
URL: http://svn.digium.com/svn-view/asterisk/trunk/build_tools/cflags.xml?view=diff&rev=187302&r1=187301&r2=187302
==============================================================================
--- trunk/build_tools/cflags.xml (original)
+++ trunk/build_tools/cflags.xml Wed Apr  8 23:59:05 2009
@@ -7,6 +7,8 @@
 		</member>
 		<member name="LOADABLE_MODULES" displayname="Runtime module loading">
 			<defaultenabled>yes</defaultenabled>
+		</member>
+		<member name="DEBUG_FD_LEAKS" displayname="Enable File Descriptor Leak Detection">
 		</member>
 		<member name="LOW_MEMORY" displayname="Optimize for Low Memory Usage">
 		</member>

Modified: trunk/include/asterisk.h
URL: http://svn.digium.com/svn-view/asterisk/trunk/include/asterisk.h?view=diff&rev=187302&r1=187301&r2=187302
==============================================================================
--- trunk/include/asterisk.h (original)
+++ trunk/include/asterisk.h Wed Apr  8 23:59:05 2009
@@ -43,7 +43,36 @@
 #define	setpriority	__PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
 #define	sched_setscheduler	__PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
 
+#if defined(DEBUG_FD_LEAKS) && !defined(STANDALONE) && !defined(STANDALONE_AEL)
+/* These includes are all about ordering */
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#define	open(a,...)	__ast_fdleak_open(__FILE__,__LINE__,__PRETTY_FUNCTION__, a, __VA_ARGS__)
+#define pipe(a)	__ast_fdleak_pipe(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
+#define socket(a,b,c)	__ast_fdleak_socket(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)
+#define close(a)	__ast_fdleak_close(a)
+#define	fopen(a,b)	__ast_fdleak_fopen(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
+#define	fclose(a)	__ast_fdleak_fclose(a)
+#define	dup2(a,b)	__ast_fdleak_dup2(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
+#define dup(a)	__ast_fdleak_dup(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
+
+int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...);
+int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func);
+int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func);
+int __ast_fdleak_close(int fd);
+FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, int line, const char *func);
+int __ast_fdleak_fclose(FILE *ptr);
+int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const char *func);
+int __ast_fdleak_dup(int oldfd, const char *file, int line, const char *func);
+#endif
+
 int ast_set_priority(int);			/*!< Provided by asterisk.c */
+int ast_fd_init(void);				/*!< Provided by astfd.c */
 
 /*!
  * \brief Register a function to be executed before Asterisk exits.

Modified: trunk/main/Makefile
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/Makefile?view=diff&rev=187302&r1=187301&r2=187302
==============================================================================
--- trunk/main/Makefile (original)
+++ trunk/main/Makefile Wed Apr  8 23:59:05 2009
@@ -22,7 +22,7 @@
 	ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
 	cdr.o tdd.o acl.o udptl.o manager.o asterisk.o \
 	dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
-	astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
+	astmm.o astfd.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
 	utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
 	netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
 	cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o \

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/asterisk.c?view=diff&rev=187302&r1=187301&r2=187302
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Wed Apr  8 23:59:05 2009
@@ -3133,6 +3133,7 @@
 	ast_utils_init();
 	tdd_init();
 	ast_tps_init();
+	ast_fd_init();
 
 	if (getenv("HOME")) 
 		snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));

Copied: trunk/main/astfd.c (from r187301, branches/1.4/main/astfd.c)
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/astfd.c?view=diff&rev=187302&p1=branches/1.4/main/astfd.c&r1=187301&p2=trunk/main/astfd.c&r2=187302
==============================================================================
--- branches/1.4/main/astfd.c (original)
+++ trunk/main/astfd.c Wed Apr  8 23:59:05 2009
@@ -227,30 +227,39 @@
 	return res;
 }
 
-static int handle_show_fd(int fd, int argc, char *argv[])
+static char *handle_show_fd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	int i;
 	char line[24];
 	struct rlimit rl;
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "core show fd";
+		e->usage =
+			"Usage: core show fd\n"
+			"       List all file descriptors currently in use and where\n"
+			"       each was opened, and with what command.\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
 	getrlimit(RLIMIT_FSIZE, &rl);
 	if (rl.rlim_cur == RLIM_INFINITY || rl.rlim_max == RLIM_INFINITY) {
 		ast_copy_string(line, "unlimited", sizeof(line));
 	} else {
 		snprintf(line, sizeof(line), "%d/%d", (int) rl.rlim_cur, (int) rl.rlim_max);
 	}
-	ast_cli(fd, "Current maxfiles: %s\n", line);
+	ast_cli(a->fd, "Current maxfiles: %s\n", line);
 	for (i = 0; i < 1024; i++) {
 		if (fdleaks[i].isopen) {
 			snprintf(line, sizeof(line), "%d", fdleaks[i].line);
-			ast_cli(fd, "%5d %15s:%-7.7s (%-25s): %s(%s)\n", i, fdleaks[i].file, line, fdleaks[i].function, fdleaks[i].callname, fdleaks[i].callargs);
-		}
-	}
-	return RESULT_SUCCESS;
-}
-
-static struct ast_cli_entry cli_show_fd =
-	{ { "core", "show", "fd", NULL },
-	handle_show_fd, "Show open file descriptors" };
+			ast_cli(a->fd, "%5d %15s:%-7.7s (%-25s): %s(%s)\n", i, fdleaks[i].file, line, fdleaks[i].function, fdleaks[i].callname, fdleaks[i].callargs);
+		}
+	}
+	return CLI_SUCCESS;
+}
+
+static struct ast_cli_entry cli_show_fd = AST_CLI_DEFINE(handle_show_fd, "Show open file descriptors");
 
 int ast_fd_init(void)
 {

Modified: trunk/main/file.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/file.c?view=diff&rev=187302&r1=187301&r2=187302
==============================================================================
--- trunk/main/file.c (original)
+++ trunk/main/file.c Wed Apr  8 23:59:05 2009
@@ -314,8 +314,10 @@
 		free(f->filename);
 	if (f->realfilename)
 		free(f->realfilename);
-	if (f->fmt->close)
-		f->fmt->close(f);
+	if (f->fmt->close) {
+		void (*closefn)(struct ast_filestream *) = f->fmt->close;
+		closefn(f);
+	}
 	if (f->f)
 		fclose(f->f);
 	if (f->vfs)
@@ -353,8 +355,9 @@
 {
 	struct ast_format *f = s->fmt;
 	int ret = -1;
-
-	if (mode == WRAP_OPEN && f->open && f->open(s))
+	int (*openfn)(struct ast_filestream *s);
+
+	if (mode == WRAP_OPEN && (openfn = f->open) && openfn(s))
 		ast_log(LOG_WARNING, "Unable to open format %s\n", f->name);
 	else if (mode == WRAP_REWRITE && f->rewrite && f->rewrite(s, comment))
 		ast_log(LOG_WARNING, "Unable to rewrite format %s\n", f->name);

Modified: trunk/utils/Makefile
URL: http://svn.digium.com/svn-view/asterisk/trunk/utils/Makefile?view=diff&rev=187302&r1=187301&r2=187302
==============================================================================
--- trunk/utils/Makefile (original)
+++ trunk/utils/Makefile Wed Apr  8 23:59:05 2009
@@ -95,7 +95,7 @@
 
 astman: astman.o md5.o
 astman: LIBS+=$(NEWT_LIB)
-astman.o: ASTCFLAGS+=-DSTANDALONE
+astman.o: ASTCFLAGS+=-DNO_MALLOC_DEBUG -DSTANDALONE
 
 stereorize: stereorize.o frame.o
 stereorize: LIBS+=-lm
@@ -210,6 +210,8 @@
 	rm ast_expr2z.o ast_expr2fz.o 
 	./check_expr2 expr2.testinput
 
+smsq.o: ASTCFLAGS+=-DSTANDALONE
+
 smsq: smsq.o strcompat.o
 smsq: LIBS+=$(POPT_LIB)
 




More information about the asterisk-commits mailing list