]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add running flag to unlang_interpret()
authorNick Porter <nick@portercomputing.co.uk>
Thu, 6 Feb 2025 17:04:31 +0000 (17:04 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Thu, 6 Feb 2025 17:04:57 +0000 (17:04 +0000)
Needed for the case when the interpreter is called to evaluate
expressions within an already running request

src/lib/io/worker.c
src/lib/unlang/interpret.c
src/lib/unlang/interpret.h
src/lib/unlang/interpret_synchronous.c
src/lib/unlang/xlat.c

index e2b2aa4df197056d1663a6687c4c61688da97810..2859e5f4958137047e017feb2b93b27db96f86b5 100644 (file)
@@ -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();
        }
index 16749ca91a52e19935e06cab14fcf9bbdf5c6ad2..d271e39d4ecd7a49b093cfd52318db76fc5f6df3 100644 (file)
@@ -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;
index 12740dbb4569642bbea08daf30584919a72b31ce..e4083bc482e7c622ee2fb7dfc130d0b3982535d3 100644 (file)
@@ -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);
 
index 74fb9811b44940ea836e597daedc52be6a1d85bf..a18949e47cce46f3d688257df0d87d48447e9f25 100644 (file)
@@ -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, "<INVALID>"));
 
index d03c559b1d0fa7fe927b272df935b5f5c20b3214..4df0d7a92f882a79110efd93ef1bbc78db30316d 100644 (file)
@@ -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;