summaryrefslogtreecommitdiff
path: root/res/res_pjproject.c
diff options
context:
space:
mode:
Diffstat (limited to 'res/res_pjproject.c')
-rw-r--r--res/res_pjproject.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/res/res_pjproject.c b/res/res_pjproject.c
index de1cecbc8..e9f0d15c4 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);