]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Make CLI "core show channel" not hold the channel lock during console output.
authorRichard Mudgett <rmudgett@digium.com>
Fri, 11 Nov 2011 17:56:51 +0000 (17:56 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Fri, 11 Nov 2011 17:56:51 +0000 (17:56 +0000)
Holding the channel lock while the CLI "core show channel" command is
executing can slow down the system.  It could block the system if the
console output is halted or paused.

* Made capture the CLI "core show channel" output into a buffer to be
output after the channel is unlocked.

* Removed use of C++ keyword as a variable name.  out renamed to obuf.

* Checked allocation of obuf for failure so will not crash.

(closes issue ASTERISK-18571)
Reported by: Pavel Troller
Tested by: rmudgett

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@344661 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/cli.c

index 407973f35dbd6912723f4585ec9a845b420ce50f..ee52f145b2e50179e9ba57058c8116052b5cb3a6 100644 (file)
@@ -1385,11 +1385,12 @@ static char *handle_showchan(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
 {
        struct ast_channel *c=NULL;
        struct timeval now;
-       struct ast_str *out = ast_str_thread_get(&ast_str_thread_global_buf, 16);
        char cdrtime[256];
        char nf[256], wf[256], rf[256];
        struct ast_str *write_transpath = ast_str_alloca(256);
        struct ast_str *read_transpath = ast_str_alloca(256);
+       struct ast_str *obuf;/*!< Buffer for variable, CDR variable, and trace output. */
+       struct ast_str *output;/*!< Accumulation buffer for all output. */
        long elapsed_seconds=0;
        int hour=0, min=0, sec=0;
 #ifdef CHANNEL_TRACE
@@ -1418,6 +1419,15 @@ static char *handle_showchan(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
                return CLI_SUCCESS;
        }
 
+       obuf = ast_str_thread_get(&ast_str_thread_global_buf, 16);
+       if (!obuf) {
+               return CLI_FAILURE;
+       }
+       output = ast_str_create(8192);
+       if (!output) {
+               return CLI_FAILURE;
+       }
+
        ast_channel_lock(c);
 
        if (c->cdr) {
@@ -1430,7 +1440,7 @@ static char *handle_showchan(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
                strcpy(cdrtime, "N/A");
        }
 
-       ast_cli(a->fd, 
+       ast_str_append(&output, 0,
                " -- General --\n"
                "           Name: %s\n"
                "           Type: %s\n"
@@ -1489,24 +1499,28 @@ static char *handle_showchan(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
                ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),
                (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
        
-       if (pbx_builtin_serialize_variables(c, &out)) {
-               ast_cli(a->fd,"      Variables:\n%s\n", ast_str_buffer(out));
+       if (pbx_builtin_serialize_variables(c, &obuf)) {
+               ast_str_append(&output, 0, "      Variables:\n%s\n", ast_str_buffer(obuf));
        }
 
-       if (c->cdr && ast_cdr_serialize_variables(c->cdr, &out, '=', '\n', 1)) {
-               ast_cli(a->fd,"  CDR Variables:\n%s\n", ast_str_buffer(out));
+       if (c->cdr && ast_cdr_serialize_variables(c->cdr, &obuf, '=', '\n', 1)) {
+               ast_str_append(&output, 0, "  CDR Variables:\n%s\n", ast_str_buffer(obuf));
        }
 
 #ifdef CHANNEL_TRACE
        trace_enabled = ast_channel_trace_is_enabled(c);
-       ast_cli(a->fd, "  Context Trace: %s\n", trace_enabled ? "Enabled" : "Disabled");
-       if (trace_enabled && ast_channel_trace_serialize(c, &out))
-               ast_cli(a->fd, "          Trace:\n%s\n", ast_str_buffer(out));
+       ast_str_append(&output, 0, "  Context Trace: %s\n",
+               trace_enabled ? "Enabled" : "Disabled");
+       if (trace_enabled && ast_channel_trace_serialize(c, &obuf)) {
+               ast_str_append(&output, 0, "          Trace:\n%s\n", ast_str_buffer(obuf));
+       }
 #endif
 
        ast_channel_unlock(c);
        c = ast_channel_unref(c);
 
+       ast_cli(a->fd, "%s", ast_str_buffer(output));
+       ast_free(output);
        return CLI_SUCCESS;
 }