<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/8742">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pjsip_scheduler.c: Sort "pjsip show scheduled_tasks" output.<br><br>* A side benefit is that the scheduled tasks are not completely blocked<br>while the CLI command executes.<br><br>* Adjusted the "Task Name" column width to have more room for longer<br>names.<br><br>Change-Id: Iec64aa463ee8b10eef90120e00c38b1fb444087e<br>---<br>M res/res_pjsip/pjsip_scheduler.c<br>1 file changed, 27 insertions(+), 14 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip/pjsip_scheduler.c b/res/res_pjsip/pjsip_scheduler.c<br>index 43a9f59..ac22aff 100644<br>--- a/res/res_pjsip/pjsip_scheduler.c<br>+++ b/res/res_pjsip/pjsip_scheduler.c<br>@@ -368,7 +368,8 @@<br> <br> static char *cli_show_tasks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)<br> {<br>- struct ao2_iterator i;<br>+ struct ao2_iterator iter;<br>+ struct ao2_container *sorted_tasks;<br> struct ast_sip_sched_task *schtd;<br> const char *log_format;<br> struct ast_tm tm;<br>@@ -377,7 +378,7 @@<br> char next_start[32];<br> int datelen;<br> struct timeval now;<br>- static const char separator[] = "======================================";<br>+ static const char separator[] = "=============================================";<br> <br> switch (cmd) {<br> case CLI_INIT:<br>@@ -393,6 +394,17 @@<br> return CLI_SHOWUSAGE;<br> }<br> <br>+ /* Get a sorted snapshot of the scheduled tasks */<br>+ sorted_tasks = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_NOLOCK, 0,<br>+ ast_sip_sched_task_sort_fn, NULL);<br>+ if (!sorted_tasks) {<br>+ return CLI_SUCCESS;<br>+ }<br>+ if (ao2_container_dup(sorted_tasks, tasks, 0)) {<br>+ ao2_ref(sorted_tasks, -1);<br>+ return CLI_SUCCESS;<br>+ }<br>+<br> now = ast_tvnow();<br> log_format = ast_logger_get_dateformat();<br> <br>@@ -401,25 +413,28 @@<br> <br> ast_cli(a->fd, "PJSIP Scheduled Tasks:\n\n");<br> <br>- ast_cli(a->fd, " %1$-24s %2$-9s %3$-9s %4$-5s %6$-*5$s %7$-*5$s %8$-*5$s %9$7s\n",<br>+ ast_cli(a->fd, "%1$-45s %2$-9s %3$-9s %4$-5s %6$-*5$s %7$-*5$s %8$-*5$s %9$7s\n",<br> "Task Name", "Interval", "Times Run", "State",<br> datelen, "Queued", "Last Started", "Next Start", "( secs)");<br> <br>- ast_cli(a->fd, " %1$-24.24s %2$-9.9s %3$-9.9s %4$-5.5s %6$-*5$.*5$s %7$-*5$.*5$s %9$-*8$.*8$s\n",<br>+ ast_cli(a->fd, "%1$-45.45s %2$-9.9s %3$-9.9s %4$-5.5s %6$-*5$.*5$s %7$-*5$.*5$s %9$-*8$.*8$s\n",<br> separator, separator, separator, separator,<br> datelen, separator, separator, datelen + 8, separator);<br> <br>-<br>- ao2_rdlock(tasks);<br>- i = ao2_iterator_init(tasks, AO2_ITERATOR_DONTLOCK);<br>- while ((schtd = ao2_iterator_next(&i))) {<br>+ iter = ao2_iterator_init(sorted_tasks, AO2_ITERATOR_UNLINK);<br>+ for (; (schtd = ao2_iterator_next(&iter)); ao2_ref(schtd, -1)) {<br> int next_run_sec;<br> struct timeval next;<br> <br> ao2_lock(schtd);<br> <br> next_run_sec = ast_sip_sched_task_get_next_run(schtd) / 1000;<br>- next = ast_tvadd(now, (struct timeval) {next_run_sec, 0});<br>+ if (next_run_sec < 0) {<br>+ /* Scheduled task is now canceled */<br>+ ao2_unlock(schtd);<br>+ continue;<br>+ }<br>+ next = ast_tvadd(now, ast_tv(next_run_sec, 0));<br> <br> ast_localtime(&schtd->when_queued, &tm, NULL);<br> ast_strftime(queued, sizeof(queued), log_format, &tm);<br>@@ -434,7 +449,7 @@<br> ast_localtime(&next, &tm, NULL);<br> ast_strftime(next_start, sizeof(next_start), log_format, &tm);<br> <br>- ast_cli(a->fd, " %1$-24.24s %2$9.3f %3$9d %4$-5s %6$-*5$s %7$-*5$s %8$-*5$s (%9$5d)\n",<br>+ ast_cli(a->fd, "%1$-46.46s%2$9.3f %3$9d %4$-5s %6$-*5$s %7$-*5$s %8$-*5$s (%9$5d)\n",<br> schtd->name,<br> schtd->interval / 1000.0,<br> schtd->run_count,<br>@@ -443,11 +458,9 @@<br> next_start,<br> next_run_sec);<br> ao2_unlock(schtd);<br>-<br>- ao2_cleanup(schtd);<br> }<br>- ao2_iterator_destroy(&i);<br>- ao2_unlock(tasks);<br>+ ao2_iterator_destroy(&iter);<br>+ ao2_ref(sorted_tasks, -1);<br> ast_cli(a->fd, "\n");<br> <br> return CLI_SUCCESS;<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8742">change 8742</a>. To unsubscribe, 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/8742"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Iec64aa463ee8b10eef90120e00c38b1fb444087e </div>
<div style="display:none"> Gerrit-Change-Number: 8742 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>