From 96fe546d0784268b4b7e6b692a299550824c2d2d Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Mon, 5 Apr 2021 22:37:12 +0100 Subject: [PATCH] Unpick some cross dependencies with detach functions --- src/lib/server/request.c | 18 ++++++++++++------ src/lib/unlang/interpret.c | 1 + src/lib/unlang/parallel.c | 2 +- src/lib/unlang/subrequest.h | 2 +- src/lib/unlang/subrequest_child.c | 11 +++-------- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/lib/server/request.c b/src/lib/server/request.c index a0d9aff574..28ac9140b4 100644 --- a/src/lib/server/request.c +++ b/src/lib/server/request.c @@ -555,14 +555,15 @@ int request_detach(request_t *child) { request_t *request = child->parent; - if (!request) return 0; /* Already detached */ - /* - * Let any signal handler that cares - * know that the child is about to - * be detached. + * Already detached or not detachable */ - unlang_interpret_signal(child, FR_SIGNAL_DETACH); + if (request_is_detached(child)) return 0; + + if (!request_is_detachable(child)) { + RERROR("Request is not detachable"); + return -1; + } /* * Unlink the child from the parent. @@ -571,6 +572,11 @@ int request_detach(request_t *child) child->parent = NULL; + /* + * Request is now detached + */ + child->type = REQUEST_TYPE_DETACHED; + return 0; } diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index afc1e07e93..3c38b060b2 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -944,6 +944,7 @@ void unlang_interpret_signal(request_t *request, fr_state_signal_t action) case FR_SIGNAL_DETACH: unlang_interpret_request_detach(request); /* Tell our caller that the request is being detached */ + request_detach(request); /* Finish detaching the request */ break; default: diff --git a/src/lib/unlang/parallel.c b/src/lib/unlang/parallel.c index a105deea35..216c2df741 100644 --- a/src/lib/unlang/parallel.c +++ b/src/lib/unlang/parallel.c @@ -346,7 +346,7 @@ static unlang_action_t unlang_parallel_process(rlm_rcode_t *p_result, request_t * Detach the child, and insert * it into the backlog. */ - if (unlang_subrequest_child_detach(child) < 0) { + if ((unlang_subrequest_lifetime_set(child) < 0) || (request_detach(request) < 0)) { talloc_free(child); RETURN_MODULE_FAIL; diff --git a/src/lib/unlang/subrequest.h b/src/lib/unlang/subrequest.h index d7251e3ecb..8c386c4174 100644 --- a/src/lib/unlang/subrequest.h +++ b/src/lib/unlang/subrequest.h @@ -37,7 +37,7 @@ typedef struct { int unique_int; //!< Session unique int identifier. } unlang_subrequest_session_t; -int unlang_subrequest_child_detach(request_t *request); +int unlang_subrequest_lifetime_set(request_t *request); int unlang_subrequest_child_push(rlm_rcode_t *out, request_t *child, unlang_subrequest_session_t const *session, diff --git a/src/lib/unlang/subrequest_child.c b/src/lib/unlang/subrequest_child.c index 60b795936d..0dcc707f78 100644 --- a/src/lib/unlang/subrequest_child.c +++ b/src/lib/unlang/subrequest_child.c @@ -80,15 +80,10 @@ static void unlang_detached_max_request_time(UNUSED fr_event_list_t *el, UNUSED * Detach it from the parent, set up it's lifetime, and mark it as * runnable. */ -int unlang_subrequest_child_detach(request_t *request) +int unlang_subrequest_lifetime_set(request_t *request) { fr_pair_t *vp; - if (request_detach(request) < 0) { - ERROR("Failed detaching child"); - return -1; - } - /* * Set Request Lifetime */ @@ -149,7 +144,7 @@ static void unlang_subrequest_child_signal(request_t *request, fr_state_signal_t state->session.unique_ptr, state->session.unique_int); - if (!fr_cond_assert(unlang_subrequest_child_detach(request) == 0)) { + if (!fr_cond_assert(unlang_subrequest_lifetime_set(request) == 0)) { REDEBUG("Child could not be detached"); return; } @@ -344,7 +339,7 @@ int unlang_subrequest_child_push_and_detach(request_t *child) */ interpret_child_init(child); - if (unlang_subrequest_child_detach(child) < 0) return -1; + if ((unlang_subrequest_lifetime_set(child) < 0) || (request_detach(child) < 0)) return -1; return 0; } -- 2.47.2