]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: add pid sample
authorWilliam Lallemand <wlallemand@haproxy.org>
Wed, 12 Jul 2023 15:43:26 +0000 (17:43 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Mon, 24 Jul 2023 15:12:29 +0000 (17:12 +0200)
Implement the pid sample fetch.

doc/configuration.txt
src/sample.c

index a054df82766171e2f13219f96e2275c35571fe86..8fcb8c2b40a3f9c987418b8e08189a8ad981f55e 100644 (file)
@@ -19600,6 +19600,10 @@ prio_offset : integer
   "http-request set-priority-offset" or "tcp-request content
   set-priority-offset".
 
+pid : integer
+  Return the PID of the current process. In most cases this is the PID of the
+  worker process.
+
 proc : integer
   Always returns value 1 (historically it would return the calling process
   number).
index 34c18a6b39abd0be94437efd8c50eefcd31828d5..daaa2cba3c68b1c2ea970b853cd7a66191f85f23 100644 (file)
@@ -4213,6 +4213,16 @@ smp_fetch_nbproc(const struct arg *args, struct sample *smp, const char *kw, voi
        return 1;
 }
 
+/* returns the PID of the current process */
+static int
+smp_fetch_pid(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       smp->data.type = SMP_T_SINT;
+       smp->data.u.sint = pid;
+       return 1;
+}
+
+
 /* returns the number of the current process (between 1 and nbproc */
 static int
 smp_fetch_proc(const struct arg *args, struct sample *smp, const char *kw, void *private)
@@ -4497,6 +4507,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "date_us",      smp_fetch_date_us,  0,         NULL, SMP_T_SINT, SMP_USE_CONST },
        { "hostname",     smp_fetch_hostname, 0,         NULL, SMP_T_STR,  SMP_USE_CONST },
        { "nbproc",       smp_fetch_nbproc,0,            NULL, SMP_T_SINT, SMP_USE_CONST },
+       { "pid",          smp_fetch_pid,   0,            NULL, SMP_T_SINT, SMP_USE_CONST },
        { "proc",         smp_fetch_proc,  0,            NULL, SMP_T_SINT, SMP_USE_CONST },
        { "quic_enabled", smp_fetch_quic_enabled, 0,     NULL, SMP_T_BOOL, SMP_USE_CONST },
        { "thread",       smp_fetch_thread,  0,          NULL, SMP_T_SINT, SMP_USE_CONST },