MINOR: tevt: Improve function to convert a termination events log to string

The function is now responsible to handle empty log because no event was
reported. In that case, an empty string is returned. It is also responsible to
handle case where termination events log is not supported for an given entity
(for instance the quic mux for now). In that case, a dash ("-") is returned.
This commit is contained in:
Christopher Faulet 2025-01-21 18:16:27 +01:00
parent b161155498
commit 487d6b09f1
2 changed files with 20 additions and 9 deletions

View File

@ -765,9 +765,19 @@ static inline const char *tevt_evts2str(uint32_t evts)
{
uint32_t evt_msk = 0xff000000;
unsigned int evt_bits = 24;
int idx;
int idx = 0;
for (idx = 0; evt_msk; evt_msk >>= 8, evt_bits -= 8) {
/* no events: do nothing */
if (!evts)
goto end;
/* -1 means the feature is not supported for the location or the entity does not exist. print a dash */
if (evts == UINT_MAX) {
tevt_evts_str[idx++] = '-';
goto end;
}
for (; evt_msk; evt_msk >>= 8, evt_bits -= 8) {
unsigned char evt = (evts & evt_msk) >> evt_bits;
unsigned int is_back;
@ -788,6 +798,7 @@ static inline const char *tevt_evts2str(uint32_t evts)
tevt_evts_str[idx++] = hextab[evt & 0xf];
}
end:
tevt_evts_str[idx] = '\0';
return tevt_evts_str;
}

View File

@ -4286,13 +4286,13 @@ static int smp_fetch_tevts(const struct arg *args, struct sample *smp, const cha
if (bconn && bconn->mux && bconn->mux->ctl)
bc_mux_ret = bconn->mux->ctl(bconn, MUX_CTL_TEVTS, NULL);
chunk_printf(trash, "{%s,", fconn ? tevt_evts2str(fconn->term_evts_log) : "-");
chunk_appendf(trash, "%s,", (fc_mux_ret != -1) ? tevt_evts2str(fc_mux_ret) : "-");
chunk_appendf(trash, "%s,", smp->strm ? tevt_evts2str(smp->strm->scf->sedesc->term_evts_log) : "-");
chunk_appendf(trash, "%s,", smp->strm ? tevt_evts2str(smp->strm->term_evts_log) : "-");
chunk_appendf(trash, "%s,", smp->strm ? tevt_evts2str(smp->strm->scb->sedesc->term_evts_log) : "-");
chunk_appendf(trash, "%s,", (bc_mux_ret != -1) ? tevt_evts2str(bc_mux_ret) : "-");
chunk_appendf(trash, "%s}", bconn ? tevt_evts2str(bconn->term_evts_log) : "-");
chunk_printf(trash, "{%s,", tevt_evts2str(fconn ? fconn->term_evts_log : -1));
chunk_appendf(trash, "%s,", tevt_evts2str(fc_mux_ret));
chunk_appendf(trash, "%s,", tevt_evts2str(smp->strm ? smp->strm->scf->sedesc->term_evts_log : -1));
chunk_appendf(trash, "%s,", tevt_evts2str(smp->strm ? smp->strm->term_evts_log : -1));
chunk_appendf(trash, "%s,", tevt_evts2str(smp->strm ? smp->strm->scb->sedesc->term_evts_log : -1));
chunk_appendf(trash, "%s,", tevt_evts2str(bc_mux_ret));
chunk_appendf(trash, "%s}", tevt_evts2str(bconn ? bconn->term_evts_log : -1));
smp->data.u.str = *trash;
smp->data.type = SMP_T_STR;