| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2009, Digium, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Tilghman Lesher <tlesher@digium.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							|  |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \file
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \brief Debugging routines for file descriptor leaks | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-09-22 20:43:30 +00:00
										 |  |  |  * \author Tilghman Lesher \verbatim <tlesher@digium.com> \endverbatim | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-15 16:20:16 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>core</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef DEBUG_FD_LEAKS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <stddef.h>
 | 
					
						
							|  |  |  | #include <time.h>
 | 
					
						
							|  |  |  | #include <sys/time.h>
 | 
					
						
							|  |  |  | #include <sys/resource.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk/cli.h"
 | 
					
						
							|  |  |  | #include "asterisk/logger.h"
 | 
					
						
							|  |  |  | #include "asterisk/options.h"
 | 
					
						
							|  |  |  | #include "asterisk/lock.h"
 | 
					
						
							|  |  |  | #include "asterisk/strings.h"
 | 
					
						
							|  |  |  | #include "asterisk/unaligned.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-19 19:49:46 +02:00
										 |  |  | #include "asterisk/localtime.h"
 | 
					
						
							|  |  |  | #include "asterisk/time.h"
 | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static struct fdleaks { | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 	const char *callname; | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 	int line; | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 	unsigned int isopen:1; | 
					
						
							|  |  |  | 	char file[40]; | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 	char function[25]; | 
					
						
							|  |  |  | 	char callargs[60]; | 
					
						
							| 
									
										
										
										
											2015-09-19 19:49:46 +02:00
										 |  |  | 	struct timeval now; | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | } fdleaks[1024] = { { "", }, }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | /* COPY does ast_copy_string(dst, src, sizeof(dst)), except:
 | 
					
						
							|  |  |  |  * - if it doesn't fit, it copies the value after the slash | 
					
						
							|  |  |  |  *   (possibly truncated) | 
					
						
							|  |  |  |  * - if there is no slash, it copies the value with the head | 
					
						
							|  |  |  |  *   truncated */ | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | #define	COPY(dst, src)                                             \
 | 
					
						
							|  |  |  | 	do {                                                           \ | 
					
						
							|  |  |  | 		int dlen = sizeof(dst), slen = strlen(src);                \ | 
					
						
							|  |  |  | 		if (slen + 1 > dlen) {                                     \ | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 			const char *slash = strrchr(src, '/');                 \ | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 			if (slash) {                                           \ | 
					
						
							|  |  |  | 				ast_copy_string(dst, slash + 1, dlen);             \ | 
					
						
							|  |  |  | 			} else {                                               \ | 
					
						
							|  |  |  | 				ast_copy_string(dst, src + slen - dlen + 1, dlen); \ | 
					
						
							|  |  |  | 			}                                                      \ | 
					
						
							|  |  |  | 		} else {                                                   \ | 
					
						
							|  |  |  | 			ast_copy_string(dst, src, dlen);                       \ | 
					
						
							|  |  |  | 		}                                                          \ | 
					
						
							|  |  |  | 	} while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define STORE_COMMON(offset, name, ...)     \
 | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 	do { \ | 
					
						
							|  |  |  | 		struct fdleaks *tmp = &fdleaks[offset]; \ | 
					
						
							| 
									
										
										
										
											2015-09-19 19:49:46 +02:00
										 |  |  | 		tmp->now = ast_tvnow(); \ | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 		COPY(tmp->file, file);      \ | 
					
						
							|  |  |  | 		tmp->line = line;           \ | 
					
						
							|  |  |  | 		COPY(tmp->function, func);  \ | 
					
						
							|  |  |  | 		tmp->callname = name;       \ | 
					
						
							|  |  |  | 		snprintf(tmp->callargs, sizeof(tmp->callargs), __VA_ARGS__); \ | 
					
						
							|  |  |  | 		tmp->isopen = 1;            \ | 
					
						
							|  |  |  | 	} while (0) | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #undef open
 | 
					
						
							|  |  |  | int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 	va_list ap; | 
					
						
							|  |  |  | 	int mode; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (flags & O_CREAT) { | 
					
						
							|  |  |  | 		va_start(ap, flags); | 
					
						
							|  |  |  | 		mode = va_arg(ap, int); | 
					
						
							|  |  |  | 		va_end(ap); | 
					
						
							|  |  |  | 		res = open(path, flags, mode); | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 		if (res > -1 && res < ARRAY_LEN(fdleaks)) { | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 			char sflags[80]; | 
					
						
							|  |  |  | 			snprintf(sflags, sizeof(sflags), "O_CREAT%s%s%s%s%s%s%s%s", | 
					
						
							|  |  |  | 				flags & O_APPEND ? "|O_APPEND" : "", | 
					
						
							|  |  |  | 				flags & O_EXCL ? "|O_EXCL" : "", | 
					
						
							|  |  |  | 				flags & O_NONBLOCK ? "|O_NONBLOCK" : "", | 
					
						
							|  |  |  | 				flags & O_TRUNC ? "|O_TRUNC" : "", | 
					
						
							|  |  |  | 				flags & O_RDWR ? "|O_RDWR" : "", | 
					
						
							| 
									
										
										
										
											2012-04-23 16:08:33 +00:00
										 |  |  | #if O_RDONLY == 0
 | 
					
						
							|  |  |  | 				!(flags & (O_WRONLY | O_RDWR)) ? "|O_RDONLY" : "", | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 				flags & O_RDONLY ? "|O_RDONLY" : "", | 
					
						
							| 
									
										
										
										
											2012-04-23 16:08:33 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 				flags & O_WRONLY ? "|O_WRONLY" : "", | 
					
						
							|  |  |  | 				""); | 
					
						
							| 
									
										
										
										
											2009-08-09 15:42:02 +00:00
										 |  |  | 			flags &= ~(O_CREAT | O_APPEND | O_EXCL | O_NONBLOCK | O_TRUNC | O_RDWR | O_RDONLY | O_WRONLY); | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 			if (flags) { | 
					
						
							|  |  |  | 				STORE_COMMON(res, "open", "\"%s\",%s|%d,%04o", path, sflags, flags, mode); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				STORE_COMMON(res, "open", "\"%s\",%s,%04o", path, sflags, mode); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		res = open(path, flags); | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 		if (res > -1 && res < ARRAY_LEN(fdleaks)) { | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 			STORE_COMMON(res, "open", "\"%s\",%d", path, flags); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef pipe
 | 
					
						
							|  |  |  | int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i, res = pipe(fds); | 
					
						
							|  |  |  | 	if (res) { | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for (i = 0; i < 2; i++) { | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 		if (fds[i] > -1 && fds[i] < ARRAY_LEN(fdleaks)) { | 
					
						
							|  |  |  | 			STORE_COMMON(fds[i], "pipe", "{%d,%d}", fds[0], fds[1]); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef socket
 | 
					
						
							|  |  |  | int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-06 15:42:46 +00:00
										 |  |  | 	char sdomain[20], stype[20], *sproto = NULL; | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 	struct protoent *pe; | 
					
						
							|  |  |  | 	int res = socket(domain, type, protocol); | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 	if (res < 0 || res >= ARRAY_LEN(fdleaks)) { | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 		return res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 15:42:46 +00:00
										 |  |  | 	if ((pe = getprotobynumber(protocol))) { | 
					
						
							|  |  |  | 		sproto = pe->p_name; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (domain == PF_UNIX) { | 
					
						
							|  |  |  | 		ast_copy_string(sdomain, "PF_UNIX", sizeof(sdomain)); | 
					
						
							|  |  |  | 	} else if (domain == PF_INET) { | 
					
						
							|  |  |  | 		ast_copy_string(sdomain, "PF_INET", sizeof(sdomain)); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		snprintf(sdomain, sizeof(sdomain), "%d", domain); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (type == SOCK_DGRAM) { | 
					
						
							|  |  |  | 		ast_copy_string(stype, "SOCK_DGRAM", sizeof(stype)); | 
					
						
							|  |  |  | 		if (protocol == 0) { | 
					
						
							|  |  |  | 			sproto = "udp"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else if (type == SOCK_STREAM) { | 
					
						
							|  |  |  | 		ast_copy_string(stype, "SOCK_STREAM", sizeof(stype)); | 
					
						
							|  |  |  | 		if (protocol == 0) { | 
					
						
							|  |  |  | 			sproto = "tcp"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		snprintf(stype, sizeof(stype), "%d", type); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 15:42:46 +00:00
										 |  |  | 	if (sproto) { | 
					
						
							|  |  |  | 		STORE_COMMON(res, "socket", "%s,%s,\"%s\"", sdomain, stype, sproto); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		STORE_COMMON(res, "socket", "%s,%s,\"%d\"", sdomain, stype, protocol); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef close
 | 
					
						
							|  |  |  | int __ast_fdleak_close(int fd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res = close(fd); | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 	if (!res && fd > -1 && fd < ARRAY_LEN(fdleaks)) { | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 		fdleaks[fd].isopen = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef fopen
 | 
					
						
							|  |  |  | FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, int line, const char *func) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	FILE *res = fopen(path, mode); | 
					
						
							|  |  |  | 	int fd; | 
					
						
							|  |  |  | 	if (!res) { | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fd = fileno(res); | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 	if (fd > -1 && fd < ARRAY_LEN(fdleaks)) { | 
					
						
							|  |  |  | 		STORE_COMMON(fd, "fopen", "\"%s\",\"%s\"", path, mode); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef fclose
 | 
					
						
							|  |  |  | int __ast_fdleak_fclose(FILE *ptr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int fd, res; | 
					
						
							|  |  |  | 	if (!ptr) { | 
					
						
							|  |  |  | 		return fclose(ptr); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fd = fileno(ptr); | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 	if ((res = fclose(ptr)) || fd < 0 || fd >= ARRAY_LEN(fdleaks)) { | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 		return res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fdleaks[fd].isopen = 0; | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef dup2
 | 
					
						
							|  |  |  | int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const char *func) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res = dup2(oldfd, newfd); | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 	if (res < 0 || res >= ARRAY_LEN(fdleaks)) { | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 		return res; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 	/* On success, newfd will be closed automatically if it was already
 | 
					
						
							|  |  |  | 	 * open. We don't need to mention anything about that, we're updating | 
					
						
							|  |  |  | 	 * the value anway. */ | 
					
						
							|  |  |  | 	STORE_COMMON(res, "dup2", "%d,%d", oldfd, newfd); /* res == newfd */ | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef dup
 | 
					
						
							|  |  |  | int __ast_fdleak_dup(int oldfd, const char *file, int line, const char *func) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res = dup(oldfd); | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 	if (res < 0 || res >= ARRAY_LEN(fdleaks)) { | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 		return res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	STORE_COMMON(res, "dup2", "%d", oldfd); | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-19 19:49:46 +02:00
										 |  |  | 	getrlimit(RLIMIT_NOFILE, &rl); | 
					
						
							| 
									
										
										
										
											2016-06-08 13:05:22 +02:00
										 |  |  | 	if (rl.rlim_cur == RLIM_INFINITY) { | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 		ast_copy_string(line, "unlimited", sizeof(line)); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2016-06-08 13:05:22 +02:00
										 |  |  | 		snprintf(line, sizeof(line), "%d", (int) rl.rlim_cur); | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	ast_cli(a->fd, "Current maxfiles: %s\n", line); | 
					
						
							| 
									
										
										
										
											2015-07-02 12:16:26 +02:00
										 |  |  | 	for (i = 0; i < ARRAY_LEN(fdleaks); i++) { | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 		if (fdleaks[i].isopen) { | 
					
						
							| 
									
										
										
										
											2015-09-19 19:49:46 +02:00
										 |  |  | 			struct ast_tm tm = {0}; | 
					
						
							|  |  |  | 			char datestring[256]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			ast_localtime(&fdleaks[i].now, &tm, NULL); | 
					
						
							|  |  |  | 			ast_strftime(datestring, sizeof(datestring), "%F %T", &tm); | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 			snprintf(line, sizeof(line), "%d", fdleaks[i].line); | 
					
						
							| 
									
										
										
										
											2015-09-19 19:49:46 +02:00
										 |  |  | 			ast_cli(a->fd, "%5d [%s] %22s:%-7.7s (%-25s): %s(%s)\n", i, datestring, fdleaks[i].file, line, fdleaks[i].function, fdleaks[i].callname, fdleaks[i].callargs); | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return CLI_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ast_cli_entry cli_show_fd = AST_CLI_DEFINE(handle_show_fd, "Show open file descriptors"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-20 15:36:10 +00:00
										 |  |  | static void fd_shutdown(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ast_cli_unregister(&cli_show_fd); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | int ast_fd_init(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-03-26 22:24:26 +00:00
										 |  |  | 	ast_register_cleanup(fd_shutdown); | 
					
						
							| 
									
										
										
										
											2009-04-09 04:59:05 +00:00
										 |  |  | 	return ast_cli_register(&cli_show_fd); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else  /* !defined(DEBUG_FD_LEAKS) */
 | 
					
						
							|  |  |  | int ast_fd_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif /* defined(DEBUG_FD_LEAKS) */
 | 
					
						
							|  |  |  | 
 |