diff options
author | Richard Mudgett <rmudgett@digium.com> | 2016-01-13 16:49:22 -0600 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2016-01-21 12:39:28 -0600 |
commit | f87c3275cc4d60871167283e621565d51b35ff8d (patch) | |
tree | 73aeb8cb0a5d48e2d442f12e0eecec70a704c50e /res/res_pjproject.c | |
parent | 09a6354f9e453c864426af0c7d79373f821983bf (diff) |
res_pjsip: Add CLI "pjsip dump endpt [details]"
Dump the res_pjsip endpt internals.
In non-developer mode we will not document or make easily accessible the
"details" option even though it is still available. The user has to know
it exists to use it. Presumably they would also be aware of the potential
crash warning below.
Warning: PJPROJECT documents that the function used by this CLI command
may cause a crash when asking for details because it tries to access all
active memory pools.
Change-Id: If2d98a3641c9873364d1daaad971376311aef3cb
Diffstat (limited to 'res/res_pjproject.c')
-rw-r--r-- | res/res_pjproject.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/res/res_pjproject.c b/res/res_pjproject.c index 9ce112388..2e092d76e 100644 --- a/res/res_pjproject.c +++ b/res/res_pjproject.c @@ -57,6 +57,19 @@ static unsigned decor_orig; static AST_VECTOR(buildopts, char *) buildopts; +/*! Protection from other log intercept instances. There can be only one at a time. */ +AST_MUTEX_DEFINE_STATIC(pjproject_log_intercept_lock); + +struct pjproject_log_intercept_data { + pthread_t thread; + int fd; +}; + +static struct pjproject_log_intercept_data pjproject_log_intercept = { + .thread = AST_PTHREADT_NULL, + .fd = -1, +}; + static void log_forwarder(int level, const char *data, int len) { int ast_level; @@ -66,6 +79,16 @@ static void log_forwarder(int level, const char *data, int len) const char *log_func = "<?>"; int mod_level; + if (pjproject_log_intercept.fd != -1 + && pjproject_log_intercept.thread == pthread_self()) { + /* + * We are handling a CLI command intercepting PJPROJECT + * log output. + */ + ast_cli(pjproject_log_intercept.fd, "%s\n", data); + return; + } + /* Lower number indicates higher importance */ switch (level) { case 0: /* level zero indicates fatal error, according to docs */ @@ -124,6 +147,23 @@ int ast_pjproject_get_buildopt(char *option, char *format_string, ...) return res; } +void ast_pjproject_log_intercept_begin(int fd) +{ + /* Protect from other CLI instances trying to do this at the same time. */ + ast_mutex_lock(&pjproject_log_intercept_lock); + + pjproject_log_intercept.thread = pthread_self(); + pjproject_log_intercept.fd = fd; +} + +void ast_pjproject_log_intercept_end(void) +{ + pjproject_log_intercept.fd = -1; + pjproject_log_intercept.thread = AST_PTHREADT_NULL; + + ast_mutex_unlock(&pjproject_log_intercept_lock); +} + void ast_pjproject_ref(void) { ast_module_ref(ast_module_info->self); |