From: Willy Tarreau Date: Fri, 6 Mar 2026 09:49:46 +0000 (+0100) Subject: MINOR: sample: store location for fetch/conv via initcalls X-Git-Tag: v3.4-dev7~60 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6e819dc4fa274089c774bd2080b3d7195ac0a9ab;p=thirdparty%2Fhaproxy.git MINOR: sample: store location for fetch/conv via initcalls Now keywords are registered with an exec_ctx and this one is passed when calling ->process. The ctx is of type INITCALL when passed via an initcall where we know the file name and line number. This was tested with and extra "malloc(15)" added in smp_fetch_path() which shows that it works: $ socat /tmp/sock1 - <<< "show profiling memory"|grep via Calls | Tot Bytes | Caller and method [via] 1893399 0 60592592 0| 0x78b2ec task_run_applet+0x3339c malloc(32) [via initcall @http_fetch.c:2416] --- diff --git a/include/haproxy/sample-t.h b/include/haproxy/sample-t.h index 27cf4bab8..1ad14522b 100644 --- a/include/haproxy/sample-t.h +++ b/include/haproxy/sample-t.h @@ -24,6 +24,7 @@ #define _HAPROXY_SAMPLE_T_H #include +#include #include /* input and output sample types @@ -265,6 +266,7 @@ struct sample_conv { unsigned int in_type; /* expected input sample type */ unsigned int out_type; /* output sample type */ void *private; /* private values. only used by maps and Lua */ + struct thread_exec_ctx exec_ctx; /* execution context */ }; /* sample conversion expression */ @@ -288,6 +290,7 @@ struct sample_fetch { unsigned int use; /* fetch source (SMP_USE_*) */ unsigned int val; /* fetch validity (SMP_VAL_*) */ void *private; /* private values. only used by Lua */ + struct thread_exec_ctx exec_ctx; /* execution context */ }; /* sample expression */ diff --git a/src/hlua.c b/src/hlua.c index 604e2d142..6e56583df 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -4926,7 +4926,7 @@ __LJMP static int hlua_run_sample_fetch(lua_State *L) /* Run the sample fetch process. */ smp_set_owner(&smp, hsmp->p, hsmp->s->sess, hsmp->s, hsmp->dir & SMP_OPT_DIR); - if (!f->process(args, &smp, f->kw, f->private)) { + if (!EXEC_CTX_WITH_RET(f->exec_ctx, f->process(args, &smp, f->kw, f->private))) { if (hsmp->flags & HLUA_F_AS_STRING) lua_pushstring(L, ""); else @@ -5059,7 +5059,7 @@ __LJMP static int hlua_run_sample_conv(lua_State *L) } /* Run the sample conversion process. */ - if (!conv->process(args, &smp, conv->private)) { + if (!EXEC_CTX_WITH_RET(conv->exec_ctx, conv->process(args, &smp, conv->private))) { if (hsmp->flags & HLUA_F_AS_STRING) lua_pushstring(L, ""); else diff --git a/src/sample.c b/src/sample.c index b29f6f3d3..4a7928595 100644 --- a/src/sample.c +++ b/src/sample.c @@ -451,6 +451,14 @@ void sample_register_fetches(struct sample_fetch_kw_list *kwl) for (bit = 0; bit < SMP_SRC_ENTRIES; bit++) if (sf->use & (1 << bit)) sf->val |= fetch_cap[bit]; + /* store declaration file/line if known */ + if (sf->exec_ctx.type) + continue; + + if (caller_initcall) { + sf->exec_ctx.type = TH_EX_CTX_INITCALL; + sf->exec_ctx.initcall = caller_initcall; + } } LIST_APPEND(&sample_fetches.list, &kwl->list); } @@ -461,6 +469,18 @@ void sample_register_fetches(struct sample_fetch_kw_list *kwl) */ void sample_register_convs(struct sample_conv_kw_list *pckl) { + struct sample_conv *sc; + + /* store declaration file/line if known */ + for (sc = pckl->kw; sc->kw != NULL; sc++) { + if (sc->exec_ctx.type) + continue; + + if (caller_initcall) { + sc->exec_ctx.type = TH_EX_CTX_INITCALL; + sc->exec_ctx.initcall = caller_initcall; + } + } LIST_APPEND(&sample_convs.list, &pckl->list); } @@ -1337,8 +1357,8 @@ int sample_process_cnv(struct sample_expr *expr, struct sample *p) } /* OK cast succeeded */ - - if (!conv_expr->conv->process(conv_expr->arg_p, p, conv_expr->conv->private)) + if (!EXEC_CTX_WITH_RET(conv_expr->conv->exec_ctx, + conv_expr->conv->process(conv_expr->arg_p, p, conv_expr->conv->private))) return 0; } return 1; @@ -1378,7 +1398,8 @@ struct sample *sample_process(struct proxy *px, struct session *sess, } smp_set_owner(p, px, sess, strm, opt); - if (!expr->fetch->process(expr->arg_p, p, expr->fetch->kw, expr->fetch->private)) + if (!EXEC_CTX_WITH_RET(expr->fetch->exec_ctx, + expr->fetch->process(expr->arg_p, p, expr->fetch->kw, expr->fetch->private))) return NULL; if (!sample_process_cnv(expr, p))