From ac87815be9601853e5e2dd6876038a127a388422 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Wed, 12 Jul 2023 17:43:26 +0200 Subject: [PATCH] MINOR: sample: add pid sample Implement the pid sample fetch. --- doc/configuration.txt | 4 ++++ src/sample.c | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/doc/configuration.txt b/doc/configuration.txt index a054df827..8fcb8c2b4 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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). diff --git a/src/sample.c b/src/sample.c index 34c18a6b3..daaa2cba3 100644 --- a/src/sample.c +++ b/src/sample.c @@ -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 },