From 02433d851412ffae9f20677a6bfea832592e632a Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Sat, 10 Aug 2019 13:42:03 -0400 Subject: [PATCH] we can have "detach" inside of an "if" statement, too --- src/lib/unlang/compile.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 5a7e81c8a30..7c8598dfea1 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -2542,8 +2542,16 @@ static unlang_t *compile_break(unlang_t *parent, unlang_compile_t *unlang_ctx, C static unlang_t *compile_detach(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF_ITEM const *ci) { - if (parent->type != UNLANG_TYPE_SUBREQUEST) { - cf_log_err(ci, "'detach' can only be used in a 'subrequest' section."); + unlang_t *subrequest; + + for (subrequest = parent; + subrequest != NULL; + subrequest = subrequest->parent) { + if (subrequest->type == UNLANG_TYPE_SUBREQUEST) break; + } + + if (!subrequest) { + cf_log_err(ci, "'detach' can only be used inside of a 'subrequest' section."); return NULL; } @@ -2551,8 +2559,8 @@ static unlang_t *compile_detach(unlang_t *parent, unlang_compile_t *unlang_ctx, * This really overloads the functionality of * cf_item_next(). */ - if (!cf_item_next(ci, ci)) { - cf_log_err(ci, "'detach' cannot be used as the last entry in a section"); + if ((parent == subrequest) && !cf_item_next(ci, ci)) { + cf_log_err(ci, "'detach' cannot be used as the last entry in a section, as there is nothing more to do"); return NULL; } -- 2.47.3