This is equivalent to `stream_generate_unique_id()`, just for checks.

Reviewed-by: Volker Dusch <[email protected]>
---
 include/haproxy/check.h |  1 +
 src/check.c             | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/haproxy/check.h b/include/haproxy/check.h
index 09e195a46..a93084cb4 100644
--- a/include/haproxy/check.h
+++ b/include/haproxy/check.h
@@ -80,6 +80,7 @@ struct task *srv_chk_io_cb(struct task *t, void *ctx, 
unsigned int state);
 int check_buf_available(void *target);
 struct buffer *check_get_buf(struct check *check, struct buffer *bptr, 
unsigned int small_buffer);
 void check_release_buf(struct check *check, struct buffer *bptr);
+struct ist check_generate_unique_id(struct check *check, struct lf_expr 
*format);
 const char *init_check(struct check *check, int type);
 void free_check(struct check *check);
 void check_purge(struct check *check);
diff --git a/src/check.c b/src/check.c
index b75a9dd57..c21d0b863 100644
--- a/src/check.c
+++ b/src/check.c
@@ -1536,6 +1536,25 @@ void check_release_buf(struct check *check, struct 
buffer *bptr)
        }
 }
 
+/* See stream_generate_unique_id(). */
+struct ist check_generate_unique_id(struct check *check, struct lf_expr 
*format)
+{
+       if (!isttest(check->unique_id)) {
+               char *unique_id;
+
+               if ((unique_id = pool_alloc(pool_head_uniqueid)) == NULL)
+                       return IST_NULL;
+
+               /* Initialize ->unique_id to an empty string to prevent infinite
+                * recursion when the <format> references %[unique-id] or %ID.
+                */
+               check->unique_id = ist2(unique_id, 0);
+               check->unique_id.len = sess_build_logline(check->sess, NULL, 
unique_id, UNIQUEID_LEN, format);
+       }
+
+       return check->unique_id;
+}
+
 const char *init_check(struct check *check, int type)
 {
        check->type = type;
-- 
2.53.0



Reply via email to