From: Alan T. DeKok Date: Mon, 14 Dec 2020 18:32:16 +0000 (-0500) Subject: add unlang_interpret_is_resumable() and use it in worker.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=555eccec75abc5da3f1aa2a9ca13bf06a4da7b65;p=thirdparty%2Ffreeradius-server.git add unlang_interpret_is_resumable() and use it in worker.c so that we can IMMEDIATELY tell if we have logic errors, as was fixed in the previous commit. Otherwise time spent debugging is time wasted. --- diff --git a/src/lib/io/worker.c b/src/lib/io/worker.c index 937b89efa2b..62893d5baf1 100644 --- a/src/lib/io/worker.c +++ b/src/lib/io/worker.c @@ -936,6 +936,20 @@ redo: break; } + /* + * If we're running a real request, then the final + * indentation MUST be zero. Otherwise we skipped + * something! + * + * Also check that the request is NOT marked as + * "yielded", but is in fact done. + * + * @todo - check that the stack is at frame 0, otherwise + * more things have gone wrong. + */ + fr_assert(request->parent || (request->log.unlang_indent == 0)); + fr_assert(!unlang_interpret_is_resumable(request)); + RDEBUG("Done request"); /* diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index 63b52a27f7c..2b87a2881e8 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -1159,6 +1159,21 @@ rlm_rcode_t unlang_interpret_stack_result(request_t *request) return stack->result; } +/** Check if a request as resumable. + * + * @param[in] request The current request. + * @return + * - true if the request is resumable (i.e. has yeilded) + * - false if the request is not resumable (i.e. has not yielded) + */ +bool unlang_interpret_is_resumable(request_t *request) +{ + unlang_stack_t *stack = request->stack; + unlang_stack_frame_t *frame = &stack->frame[stack->depth]; + + return is_yielded(frame); +} + /** Mark a request as resumable. * * It's not called "unlang_interpret", because it doesn't actually diff --git a/src/lib/unlang/interpret.h b/src/lib/unlang/interpret.h index 043c3af4c8a..2fd8f3152ed 100644 --- a/src/lib/unlang/interpret.h +++ b/src/lib/unlang/interpret.h @@ -116,6 +116,8 @@ void *unlang_interpret_stack_alloc(TALLOC_CTX *ctx); void unlang_interpret_mark_resumable(request_t *request); +bool unlang_interpret_is_resumable(request_t *request); + void unlang_interpret_signal(request_t *request, fr_state_signal_t action); int unlang_interpret_stack_depth(request_t *request);