<p>Harald Welte <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/14363">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">fsm: Reduce amount of copy+pasted LOGPFSMSRC() statements<br><br>Instead of copy+pasting the same LOGPFSMSRC("State change to " ...)<br>with slightly different trailer depending on the FSM timer, let's first<br>snprintf() to a stack variable and then have a single log statement.<br><br>Change-Id: I49528c4ca1fa11aef09c2092615dccca450b847c<br>---<br>M src/fsm.c<br>1 file changed, 15 insertions(+), 17 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/fsm.c b/src/fsm.c</span><br><span>index 37da9f9..337786d 100644</span><br><span>--- a/src/fsm.c</span><br><span>+++ b/src/fsm.c</span><br><span>@@ -609,33 +609,31 @@</span><br><span>                 st->onleave(fi, new_state);</span><br><span> </span><br><span>   if (fsm_log_timeouts) {</span><br><span style="color: hsl(120, 100%, 40%);">+               char trailer[64];</span><br><span style="color: hsl(120, 100%, 40%);">+             trailer[0] = '\0';</span><br><span>           if (keep_timer && fi->timer.active) {</span><br><span>                     /* This should always give us a timeout, but just in case the return value indicates error, omit</span><br><span>                      * logging the remaining time. */</span><br><span>                    if (osmo_timer_remaining(&fi->timer, NULL, &remaining))</span><br><span style="color: hsl(0, 100%, 40%);">-                              LOGPFSMSRC(fi, file, line,</span><br><span style="color: hsl(0, 100%, 40%);">-                                         "State change to %s (keeping " OSMO_T_FMT ")\n",</span><br><span style="color: hsl(0, 100%, 40%);">-                                    osmo_fsm_state_name(fsm, new_state),</span><br><span style="color: hsl(0, 100%, 40%);">-                                    OSMO_T_FMT_ARGS(fi->T));</span><br><span style="color: hsl(120, 100%, 40%);">+                                snprintf(trailer, sizeof(trailer), "(keeping " OSMO_T_FMT ")",</span><br><span style="color: hsl(120, 100%, 40%);">+                                     OSMO_T_FMT_ARGS(fi->T));</span><br><span>                         else</span><br><span style="color: hsl(0, 100%, 40%);">-                            LOGPFSMSRC(fi, file, line,</span><br><span style="color: hsl(0, 100%, 40%);">-                                         "State change to %s (keeping " OSMO_T_FMT ", %ld.%03lds remaining)\n",</span><br><span style="color: hsl(0, 100%, 40%);">-                                      osmo_fsm_state_name(fsm, new_state),</span><br><span style="color: hsl(0, 100%, 40%);">-                                    OSMO_T_FMT_ARGS(fi->T), remaining.tv_sec, remaining.tv_usec / 1000);</span><br><span style="color: hsl(120, 100%, 40%);">+                            snprintf(trailer, sizeof(trailer), "(keeping " OSMO_T_FMT</span><br><span style="color: hsl(120, 100%, 40%);">+                                     ", %ld.%03lds remaining)", OSMO_T_FMT_ARGS(fi->T),</span><br><span style="color: hsl(120, 100%, 40%);">+                                       remaining.tv_sec, remaining.tv_usec / 1000);</span><br><span>               } else if (timeout_ms) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        if (timeout_ms % 1000 == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 if (timeout_ms % 1000 == 0)</span><br><span>                          /* keep log output legacy compatible to avoid autotest failures */</span><br><span style="color: hsl(0, 100%, 40%);">-                              LOGPFSMSRC(fi, file, line, "State change to %s (" OSMO_T_FMT ", %lus)\n",</span><br><span style="color: hsl(0, 100%, 40%);">-                                      osmo_fsm_state_name(fsm, new_state),</span><br><span style="color: hsl(120, 100%, 40%);">+                               snprintf(trailer, sizeof(trailer), "(" OSMO_T_FMT ", %lus)",</span><br><span>                                        OSMO_T_FMT_ARGS(T), timeout_ms/1000);</span><br><span style="color: hsl(0, 100%, 40%);">-                        } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                                LOGPFSMSRC(fi, file, line, "State change to %s (" OSMO_T_FMT ", %lums)\n",</span><br><span style="color: hsl(0, 100%, 40%);">-                                     osmo_fsm_state_name(fsm, new_state),</span><br><span style="color: hsl(120, 100%, 40%);">+                       else</span><br><span style="color: hsl(120, 100%, 40%);">+                          snprintf(trailer, sizeof(trailer), "(" OSMO_T_FMT ", %lums)",</span><br><span>                                       OSMO_T_FMT_ARGS(T), timeout_ms);</span><br><span style="color: hsl(0, 100%, 40%);">-                     }</span><br><span>            } else</span><br><span style="color: hsl(0, 100%, 40%);">-                  LOGPFSMSRC(fi, file, line, "State change to %s (no timeout)\n",</span><br><span style="color: hsl(0, 100%, 40%);">-                                  osmo_fsm_state_name(fsm, new_state));</span><br><span style="color: hsl(120, 100%, 40%);">+                      snprintf(trailer, sizeof(trailer), "(no timeout)");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+               LOGPFSMSRC(fi, file, line, "State change to %s %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                          osmo_fsm_state_name(fsm, new_state), trailer);</span><br><span>    } else {</span><br><span>             LOGPFSMSRC(fi, file, line, "state_chg to %s\n",</span><br><span>                       osmo_fsm_state_name(fsm, new_state));</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/14363">change 14363</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.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.osmocom.org/c/libosmocore/+/14363"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I49528c4ca1fa11aef09c2092615dccca450b847c </div>
<div style="display:none"> Gerrit-Change-Number: 14363 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-MessageType: merged </div>