From: Nick Porter Date: Thu, 6 Feb 2025 17:04:31 +0000 (+0000) Subject: Add running flag to unlang_interpret() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f149d2964a7834fa0d2041b62bfcac48ff33cca;p=thirdparty%2Ffreeradius-server.git Add running flag to unlang_interpret() Needed for the case when the interpreter is called to evaluate expressions within an already running request --- diff --git a/src/lib/io/worker.c b/src/lib/io/worker.c index e2b2aa4df19..2859e5f4958 100644 --- a/src/lib/io/worker.c +++ b/src/lib/io/worker.c @@ -1335,7 +1335,7 @@ static inline CC_HINT(always_inline) void worker_run_request(fr_worker_t *worker return; } - (void)unlang_interpret(request); + (void)unlang_interpret(request, UNLANG_REQUEST_RESUME); now = fr_time(); } diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index 16749ca91a5..d271e39d4ec 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -765,9 +765,10 @@ unlang_frame_action_t frame_eval(request_t *request, unlang_stack_frame_t *frame * * @param[in] request to run. If this is an internal request * the request may be freed by the interpreter. + * @param[in] running Is the interpreter already running. * @return The final request rcode. */ -CC_HINT(hot) rlm_rcode_t unlang_interpret(request_t *request) +CC_HINT(hot) rlm_rcode_t unlang_interpret(request_t *request, bool running) { unlang_frame_action_t fa = UNLANG_FRAME_ACTION_NEXT; rlm_rcode_t rcode; @@ -790,7 +791,7 @@ CC_HINT(hot) rlm_rcode_t unlang_interpret(request_t *request) fr_assert_msg(intp, "request has no interpreter associated"); RDEBUG4("** [%i] %s - interpret entered", stack->depth, __FUNCTION__); - intp->funcs.resume(request, intp->uctx); + if (!running) intp->funcs.resume(request, intp->uctx); for (;;) { fr_assert(request->master_state != REQUEST_STOP_PROCESSING); @@ -907,6 +908,9 @@ CC_HINT(hot) rlm_rcode_t unlang_interpret(request_t *request) continue; case UNLANG_FRAME_ACTION_YIELD: + /* Cannot yield from a nested call to unlang_interpret */ + fr_assert(!running); + RDEBUG4("** [%i] %s - interpret yielding", stack->depth, __FUNCTION__); intp->funcs.yield(request, intp->uctx); return stack->result; diff --git a/src/lib/unlang/interpret.h b/src/lib/unlang/interpret.h index 12740dbb456..e4083bc482e 100644 --- a/src/lib/unlang/interpret.h +++ b/src/lib/unlang/interpret.h @@ -38,6 +38,9 @@ extern "C" { #define UNLANG_STACK_MAX (64) //!< The maximum depth of the stack. #define UNLANG_FRAME_PRE_ALLOC (128) //!< How much memory we pre-alloc for each frame. +#define UNLANG_REQUEST_RUNNING (true) +#define UNLANG_REQUEST_RESUME (false) + /** Interpreter handle * */ @@ -142,7 +145,7 @@ void unlang_interpret_set_thread_default(unlang_interpret_t *intp); unlang_interpret_t *unlang_interpret_get_thread_default(void); -rlm_rcode_t unlang_interpret(request_t *request) CC_HINT(hot); +rlm_rcode_t unlang_interpret(request_t *request, bool running) CC_HINT(hot); rlm_rcode_t unlang_interpret_synchronous(fr_event_list_t *el, request_t *request); diff --git a/src/lib/unlang/interpret_synchronous.c b/src/lib/unlang/interpret_synchronous.c index 74fb9811b44..a18949e47cc 100644 --- a/src/lib/unlang/interpret_synchronous.c +++ b/src/lib/unlang/interpret_synchronous.c @@ -230,7 +230,7 @@ rlm_rcode_t unlang_interpret_synchronous(fr_event_list_t *el, request_t *request el = intps->el; - rcode = unlang_interpret(request); + rcode = unlang_interpret(request, UNLANG_REQUEST_RESUME); while ((dont_wait_for_event = (fr_heap_num_elements(intps->runnable) > 0)) || (intps->yielded > 0)) { @@ -285,7 +285,7 @@ rlm_rcode_t unlang_interpret_synchronous(fr_event_list_t *el, request_t *request * do another loop around. */ RDEBUG4(">>> interpreter (iteration %i)", ++iterations); - sub_rcode = unlang_interpret(sub_request); + sub_rcode = unlang_interpret(sub_request, UNLANG_REQUEST_RESUME); RDEBUG4("<<< interpreter (iteration %i) - %s", iterations, fr_table_str_by_value(rcode_table, sub_rcode, "")); diff --git a/src/lib/unlang/xlat.c b/src/lib/unlang/xlat.c index d03c559b1d0..4df0d7a92f8 100644 --- a/src/lib/unlang/xlat.c +++ b/src/lib/unlang/xlat.c @@ -747,7 +747,7 @@ int unlang_xlat_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *reque if (unlang_xlat_push(ctx, &success, out, request, xlat, UNLANG_TOP_FRAME) < 0) return -1; - (void) unlang_interpret(request); + (void) unlang_interpret(request, UNLANG_REQUEST_RUNNING); if (!success) return -1;