]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tevt: Improve function to convert a termination events log to string
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 21 Jan 2025 17:16:27 +0000 (18:16 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 31 Jan 2025 09:41:50 +0000 (10:41 +0100)
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.

include/haproxy/connection.h
src/stream.c

index 33607ea3a265bd10e360957dd8f99c0f8d46a78a..a76f0ac1365170e30b0c906be5cc43769d59a571 100644 (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;
 }
index e85c2f61242184cc2e8799195dc0de151aa5d956..d0a4a96d466d0ae01d10c7cf9d283f10858a6e98 100644 (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;