]> git.kaiwu.me - haproxy.git/commitdiff
CLEANUP: log: Stop touching `struct stream` internals for `%ID`
authorTim Duesterhus <tim@bastelstu.be>
Mon, 13 Apr 2026 17:37:29 +0000 (19:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 13 Apr 2026 18:01:42 +0000 (20:01 +0200)
Use the return value of `stream_generate_unique_id()` instead of relying on the
`unique_id` field of `struct stream` when handling the `%ID` log placeholder.
This also allowed to unify the "stream available" and "stream not available"
paths.

Reviewed-by: Volker Dusch <github@wallbash.com>
src/log.c

index 8d51f0c93e924e1a620d48ff36d6ad5904aac903..b669be627f001a1cb2aa92d594a0a53bc0875b2c 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -5171,20 +5171,18 @@ size_t sess_build_logline_orig(struct session *sess, struct stream *s,
                                break;
 
                        case LOG_FMT_UNIQUEID: // %ID
-                               ret = NULL;
-                               if (s) {
-                                       /* if unique-id was not generated */
-                                       if (!isttest(s->unique_id) && !lf_expr_isempty(&sess->fe->format_unique_id)) {
-                                               stream_generate_unique_id(s, &sess->fe->format_unique_id);
-                                       }
-                                       ret = lf_text_len(tmplog, s->unique_id.ptr, s->unique_id.len, maxsize - (tmplog - dst), ctx);
-                               }
-                               else
-                                       ret = lf_text_len(tmplog, NULL, 0, maxsize - (tmplog - dst), ctx);
+                       {
+                               struct ist unique_id = IST_NULL;
+
+                               if (s && !lf_expr_isempty(&sess->fe->format_unique_id))
+                                       unique_id = stream_generate_unique_id(s, &sess->fe->format_unique_id);
+
+                               ret = lf_text_len(tmplog, istptr(unique_id), istlen(unique_id), maxsize - (tmplog - dst), ctx);
                                if (ret == NULL)
                                        goto out;
                                tmplog = ret;
                                break;
+                       }
 
                        case LOG_FMT_ORIGIN: // %OG
                                ret = lf_text(tmplog, log_orig_to_str(log_orig.id),