<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16093">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  George Joseph: Looks good to me, approved; Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_lock: Add "dialplan locks show" cli command.<br><br>For example:<br><br>arthur*CLI> dialplan locks show<br>func_lock locks:<br>Name                                     Requesters Owner<br>uls-autoref                              0          (unlocked)<br>1 total locks listed.<br><br>Obviously other potentially useful stats could be added (eg, how many<br>times there was contention, how many times it failed etc ... but that<br>would require keeping the stats and I'm not convinced that's worth the<br>effort.  This was useful to troubleshoot some other issues so submitting<br>it.<br><br>Change-Id: Ib875e56feb49d523300aec5f36c635ed74843a9f<br>Signed-off-by: Jaco Kroon <jaco@uls.co.za><br>---<br>M funcs/func_lock.c<br>1 file changed, 37 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/funcs/func_lock.c b/funcs/func_lock.c</span><br><span>index ccd1150..ffcd61c 100644</span><br><span>--- a/funcs/func_lock.c</span><br><span>+++ b/funcs/func_lock.c</span><br><span>@@ -42,6 +42,7 @@</span><br><span> #include "asterisk/linkedlists.h"</span><br><span> #include "asterisk/astobj2.h"</span><br><span> #include "asterisk/utils.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/cli.h"</span><br><span> </span><br><span> /*** DOCUMENTATION</span><br><span>   <function name="LOCK" language="en_US"></span><br><span>@@ -430,6 +431,37 @@</span><br><span>     return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static char *handle_cli_locks_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   int c = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+    struct lock_frame* current;</span><br><span style="color: hsl(120, 100%, 40%);">+   switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+        case CLI_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+                e->command = "dialplan locks show";</span><br><span style="color: hsl(120, 100%, 40%);">+              e->usage =</span><br><span style="color: hsl(120, 100%, 40%);">+                 "Usage: dialplan locks show\n"</span><br><span style="color: hsl(120, 100%, 40%);">+                      "       List all locks known to func_lock, along with their current status.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  case CLI_GENERATE:</span><br><span style="color: hsl(120, 100%, 40%);">+            return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   ast_cli(a->fd, "func_lock locks:\n");</span><br><span style="color: hsl(120, 100%, 40%);">+    ast_cli(a->fd, "%-40s Requesters Owner\n", "Name");</span><br><span style="color: hsl(120, 100%, 40%);">+    AST_LIST_LOCK(&locklist);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_LIST_TRAVERSE(&locklist, current, entries) {</span><br><span style="color: hsl(120, 100%, 40%);">+          ast_mutex_lock(&current->mutex);</span><br><span style="color: hsl(120, 100%, 40%);">+               ast_cli(a->fd, "%-40s %-10d %s\n", current->name, current->requesters,</span><br><span style="color: hsl(120, 100%, 40%);">+                             current->owner ? ast_channel_name(current->owner) : "(unlocked)");</span><br><span style="color: hsl(120, 100%, 40%);">+            ast_mutex_unlock(&current->mutex);</span><br><span style="color: hsl(120, 100%, 40%);">+             c++;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+     AST_LIST_UNLOCK(&locklist);</span><br><span style="color: hsl(120, 100%, 40%);">+       ast_cli(a->fd, "%d total locks listed.\n", c);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static struct ast_custom_function lock_function = {</span><br><span>        .name = "LOCK",</span><br><span>    .read = lock_read,</span><br><span>@@ -448,6 +480,8 @@</span><br><span>     .read_max = 2,</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_cli_entry cli_locks_show = AST_CLI_DEFINE(handle_cli_locks_show, "List func_lock locks.");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int unload_module(void)</span><br><span> {</span><br><span>    struct lock_frame *current;</span><br><span>@@ -460,6 +494,8 @@</span><br><span>    ast_custom_function_unregister(&lock_function);</span><br><span>  ast_custom_function_unregister(&trylock_function);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    ast_cli_unregister(&cli_locks_show);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>   AST_LIST_LOCK(&locklist);</span><br><span>        while ((current = AST_LIST_REMOVE_HEAD(&locklist, entries))) {</span><br><span>           int warned = 0;</span><br><span>@@ -498,6 +534,7 @@</span><br><span>        int res = ast_custom_function_register_escalating(&lock_function, AST_CFE_READ);</span><br><span>         res |= ast_custom_function_register_escalating(&trylock_function, AST_CFE_READ);</span><br><span>         res |= ast_custom_function_register_escalating(&unlock_function, AST_CFE_READ);</span><br><span style="color: hsl(120, 100%, 40%);">+   res |= ast_cli_register(&cli_locks_show);</span><br><span> </span><br><span>    return res;</span><br><span> }</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16093">change 16093</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16093"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: Ib875e56feb49d523300aec5f36c635ed74843a9f </div>
<div style="display:none"> Gerrit-Change-Number: 16093 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-CC: Jaco Kroon <jaco@uls.co.za> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>