]> git.kaiwu.me - haproxy.git/commitdiff
CLEANUP: debug/tree-wide: replace COUNT_IF(1, ...) with COUNT()
authorWilly Tarreau <w@1wt.eu>
Fri, 6 Nov 2026 15:17:00 +0000 (16:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 Nov 2026 15:19:32 +0000 (16:19 +0100)
This patch replaces 28 occurrences of COUNT_IF(1, msg) with COUNT(msg).
This makes the counters output more readable, the code as well, and even
saves a few bytes (148) in the executable.

include/haproxy/http.h
src/ev_epoll.c
src/mux_h1.c
src/mux_quic.c
src/quic_rx.c
src/sock.c
src/stream.c

index 2b2832fea5974f49f81907ee4d0a2dd1a4a49f76..8ff8327bf5f14cec962d91eba4e71095d78a9e12 100644 (file)
@@ -134,9 +134,9 @@ static inline void http_reset_hardening_check(struct http_hdng_chk *chk)
        int _ret = 0;                                                         \
        if (unlikely((http_hdng_chk.rules | ~http_hdng_chk.found) & _flag)) { \
                http_hdng_chk.found |= _flag;                                 \
-               (void)COUNT_IF(1, "hardening " #flag " condition met");       \
+               COUNT("hardening " #flag " condition met");                   \
                if (http_hdng_chk.rules & _flag) {                            \
-                       (void)COUNT_IF(1, "hardening " #flag " enforced");    \
+                       COUNT("hardening " #flag " enforced");                \
                        http_hdng_chk.fixed |= _flag;                         \
                        _ret = 1;                                             \
                }                                                             \
index 5e205fe6917050a820f4b3094f30cfe395e9142d..6183d449a68754980f8c0a9a795d2b14debadea6 100644 (file)
@@ -293,7 +293,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
                                         * events for statistics purposes.
                                         */
                                        if (e & (EPOLLRDHUP|EPOLLHUP|EPOLLERR))
-                                               COUNT_IF(1, "epoll report of HUP/ERR on a stale fd reopened on another thread (harmless)");
+                                               COUNT("epoll report of HUP/ERR on a stale fd reopened on another thread (harmless)");
                                } else {
                                        /* same thread but different generation, this smells bad,
                                         * maybe that could be caused by crossed takeovers with a
@@ -303,16 +303,16 @@ static void _do_poll(struct poller *p, int exp, int wake)
                                         * once we've read all pending data.
                                         */
                                        if (e & EPOLLERR)
-                                               COUNT_IF(1, "epoll report of ERR on a stale fd reopened on the same thread (suspicious)");
+                                               COUNT("epoll report of ERR on a stale fd reopened on the same thread (suspicious)");
                                        else if (e & (EPOLLRDHUP|EPOLLHUP))
-                                               COUNT_IF(1, "epoll report of HUP on a stale fd reopened on the same thread (suspicious)");
+                                               COUNT("epoll report of HUP on a stale fd reopened on the same thread (suspicious)");
                                        else
-                                               COUNT_IF(1, "epoll report of a harmless event on a stale fd reopened on the same thread (suspicious)");
+                                               COUNT("epoll report of a harmless event on a stale fd reopened on the same thread (suspicious)");
                                }
                        } else if (ev_gen + 1 != fd_gen) {
-                               COUNT_IF(1, "epoll report of event on a closed recycled fd (rare)");
+                               COUNT("epoll report of event on a closed recycled fd (rare)");
                        } else {
-                               COUNT_IF(1, "epoll report of event on a just closed fd (harmless)");
+                               COUNT("epoll report of event on a just closed fd (harmless)");
                        }
                        continue;
                } else if (fd_tgid(fd) != tgid) {
index 3b6e479f67d262673305cad7df432ed7d90834ed..032e1865d1429cbe76f98d022b9506b52a4c787d 100644 (file)
@@ -3158,7 +3158,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf,
 
                if (h1m->flags & H1_MF_CLEN) {
                        if (count > h1m->curr_len) {
-                               COUNT_IF(1, "more payload than announced (0-copy)");
+                               COUNT("more payload than announced (0-copy)");
                                TRACE_ERROR("more payload than announced",
                                            H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
                                goto error;
@@ -3182,7 +3182,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf,
                        /* If is a new chunk, prepend the chunk size */
                        if (h1m->state == H1_MSG_CHUNK_CRLF || h1m->state == H1_MSG_CHUNK_SIZE) {
                                if (h1m->curr_len) {
-                                       COUNT_IF(1, "chunk bigger than announced (0-copy)");
+                                       COUNT("chunk bigger than announced (0-copy)");
                                        TRACE_ERROR("chunk bigger than announced",
                                                    H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
                                        goto error;
@@ -3211,7 +3211,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf,
                        /* It is the end of the message, add the last chunk with the extra CRLF */
                        if (eom) {
                                if (h1m->curr_len) {
-                                       COUNT_IF(1, "chunk smaller than announced (0-copy)");
+                                       COUNT("chunk smaller than announced (0-copy)");
                                        TRACE_ERROR("chunk smaller than announced",
                                                    H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
                                        goto error;
@@ -3236,7 +3236,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf,
        /* Handle now case of CRLF at the end of a chun. */
        if ((h1m->flags & H1_MF_CHNK) && h1m->state == H1_MSG_CHUNK_CRLF) {
                if (h1m->curr_len) {
-                       COUNT_IF(1, "chunk bigger than announced");
+                       COUNT("chunk bigger than announced");
                        TRACE_ERROR("chunk bigger than announced",
                                    H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
                        goto error;
@@ -3311,7 +3311,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf,
 
                        if (h1m->flags & H1_MF_CLEN) {
                                if (vlen > h1m->curr_len) {
-                                       COUNT_IF(1, "more payload than announced");
+                                       COUNT("more payload than announced");
                                        TRACE_ERROR("more payload than announced",
                                                    H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
                                        goto error;
@@ -3328,7 +3328,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf,
                                }
                                if (last_data) {
                                        if (h1m->curr_len) {
-                                               COUNT_IF(1, "chunk smaller than announced");
+                                               COUNT("chunk smaller than announced");
                                                TRACE_ERROR("chunk smaller than announced",
                                                            H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
                                                goto error;
@@ -3349,7 +3349,7 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf,
                        }
                        else if (h1m->flags & H1_MF_CHNK) {
                                if (h1m->curr_len) {
-                                       COUNT_IF(1, "chunk smaller than announced");
+                                       COUNT("chunk smaller than announced");
                                        TRACE_ERROR("chunk smaller than announced",
                                                    H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
                                        goto error;
@@ -4863,7 +4863,7 @@ static void h1_detach(struct sedesc *sd)
                h1c->state = H1_CS_DRAINING;
                h1c->flags &= ~H1C_F_WANT_FASTFWD;
                h1c_report_term_evt(h1c, muxc_tevt_type_graceful_shut);
-               COUNT_IF(1, "Deferring H1S destroy to drain message");
+               COUNT("Deferring H1S destroy to drain message");
                TRACE_DEVEL("Deferring H1S destroy to drain message", H1_EV_STRM_END, h1s->h1c->conn, h1s);
                /* If we have a pending data, process it immediately or
                 * subscribe for reads waiting for new data
@@ -5539,7 +5539,7 @@ static int h1_fastfwd(struct stconn *sc, unsigned int count, unsigned int flags)
                if ((uint64_t)total > h1m->curr_len) {
                        h1s->flags |= H1S_F_PARSING_ERROR;
                        se_fl_set(h1s->sd, SE_FL_ERROR);
-                       COUNT_IF(1, "more payload than announced");
+                       COUNT("more payload than announced");
                        TRACE_ERROR("too much payload, more than announced",
                                    H1_EV_STRM_RECV|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
                        goto end;
index 769b6eb680037147e7844feccb8a218609c1824b..484c6af7804905ac7476d656035654816240bcc5 100644 (file)
@@ -2724,7 +2724,7 @@ static void qcs_destroy(struct qcs *qcs)
         * the connection flow control consistency
         */
        if (!qcs_is_close_remote(qcs) && qcs->rx.offset_max > qcs->rx.offset) {
-               COUNT_IF(1, "QCS is released while not remotely closed. "
+               COUNT("QCS is released while not remotely closed. "
                            "This may cause miscalculation in conn flow control.");
                qcc_account_for_conn_fctl(qcc, qcs->rx.offset_max - qcs->rx.offset);
        }
index 5dff2f3987dcf7a6104f71b81984f7de702339db..74e3f79a58603528a1c82265b7114200d0deb431 100644 (file)
@@ -757,7 +757,7 @@ static int qc_handle_crypto_frm(struct quic_conn *qc,
                 */
                if (ncbmb_head(ncbuf) + data >= ncbmb_wrap(ncbuf)) {
                        TRACE_ERROR("unsupported wrapping CRYPTO frames", QUIC_EV_CONN_PRSHPKT, qc);
-                       COUNT_IF(1, "connection closed on unsupported wrapping CRYPTO content");
+                       COUNT("connection closed on unsupported wrapping CRYPTO content");
                        quic_set_connection_close(qc, quic_err_transport(QC_ERR_CRYPTO_BUFFER_EXCEEDED));
                        quic_free_ncbuf(ncbuf);
                        goto err;
index a5a6f6e2c98924e123278d16ce86d4b521ba7686..071a6fe30e167d51ba72b9ee474de5a95b91a016 100644 (file)
@@ -1020,7 +1020,7 @@ int sock_conn_check(struct connection *conn)
                 *   - https://www.spinics.net/lists/netdev/msg876470.html
                 */
                if (unlikely((fdtab[fd].state & (FD_POLL_HUP|FD_POLL_ERR)) == FD_POLL_HUP)) {
-                       COUNT_IF(1, "Removing FD_POLL_HUP if no FD_POLL_ERR to let connect() decide");
+                       COUNT("Removing FD_POLL_HUP if no FD_POLL_ERR to let connect() decide");
                        fdtab[fd].state &= ~FD_POLL_HUP;
                }
 
index efa83e1f158316e6e511869268b0a4f414e4be73..87817c2a1eec4d51d748d66777e8eb0c27e268cb 100644 (file)
@@ -2049,7 +2049,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                        sc_abort(scf);
                        sc_shutdown(scf);
                        if (!(req->analysers) && !(res->analysers)) {
-                               COUNT_IF(1, "Report a client abort (no analysers)");
+                               COUNT("Report a client abort (no analysers)");
                                if (s->be_tgcounters)
                                        _HA_ATOMIC_INC(&s->be_tgcounters->cli_aborts);
                                if (sess->fe_tgcounters)
@@ -2075,7 +2075,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                        if (s->sv_tgcounters)
                                _HA_ATOMIC_INC(&s->sv_tgcounters->failed_resp);
                        if (!(req->analysers) && !(res->analysers)) {
-                               COUNT_IF(1, "Report a client abort (no analysers)");
+                               COUNT("Report a client abort (no analysers)");
                                if (s->be_tgcounters)
                                        _HA_ATOMIC_INC(&s->be_tgcounters->srv_aborts);
                                if (sess->fe_tgcounters)
@@ -2396,7 +2396,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                                if (s->sv_tgcounters)
                                        _HA_ATOMIC_INC(&s->sv_tgcounters->cli_aborts);
                                s->flags |= SF_ERR_CLICL;
-                               COUNT_IF(1, "Report unhandled client error");
+                               COUNT("Report unhandled client error");
                        }
                        else if (req->flags & CF_READ_TIMEOUT) {
                                if (s->be_tgcounters)
@@ -2408,7 +2408,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                                if (s->sv_tgcounters)
                                        _HA_ATOMIC_INC(&s->sv_tgcounters->cli_aborts);
                                s->flags |= SF_ERR_CLITO;
-                               COUNT_IF(1, "Report unhandled client timeout (RD)");
+                               COUNT("Report unhandled client timeout (RD)");
                        }
                        else {
                                if (s->be_tgcounters)
@@ -2420,7 +2420,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                                if (s->sv_tgcounters)
                                        _HA_ATOMIC_INC(&s->sv_tgcounters->srv_aborts);
                                s->flags |= SF_ERR_SRVTO;
-                               COUNT_IF(1, "Report unhandled server timeout (WR)");
+                               COUNT("Report unhandled server timeout (WR)");
                        }
                        sess_set_term_flags(s);
 
@@ -2452,7 +2452,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                                if (s->sv_tgcounters)
                                        _HA_ATOMIC_INC(&s->sv_tgcounters->srv_aborts);
                                s->flags |= SF_ERR_SRVCL;
-                               COUNT_IF(1, "Report unhandled server error");
+                               COUNT("Report unhandled server error");
                        }
                        else if (res->flags & CF_READ_TIMEOUT) {
                                if (s->be_tgcounters)
@@ -2464,7 +2464,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                                if (s->sv_tgcounters)
                                        _HA_ATOMIC_INC(&s->sv_tgcounters->srv_aborts);
                                s->flags |= SF_ERR_SRVTO;
-                               COUNT_IF(1, "Report unhandled server timeout (RD)");
+                               COUNT("Report unhandled server timeout (RD)");
                        }
                        else {
                                if (s->be_tgcounters)
@@ -2476,7 +2476,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                                if (s->sv_tgcounters)
                                        _HA_ATOMIC_INC(&s->sv_tgcounters->cli_aborts);
                                s->flags |= SF_ERR_CLITO;
-                               COUNT_IF(1, "Report unhandled client timeout (WR)");
+                               COUNT("Report unhandled client timeout (WR)");
                        }
                        sess_set_term_flags(s);
                }