]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Have cancel xlat execute immediately when timeout value is zero
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 5 Mar 2024 16:37:52 +0000 (10:37 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 5 Mar 2024 16:38:14 +0000 (10:38 -0600)
src/lib/unlang/interpret.c

index d330a71aa1ee46507366368e8ea36eb599104fea..7674008a9666e4ca1fada4b7a38d6e4f264e3d0e 100644 (file)
@@ -27,6 +27,8 @@ RCSID("$Id$")
 #include <freeradius-devel/server/base.h>
 #include <freeradius-devel/server/modpriv.h>
 #include <freeradius-devel/unlang/xlat_func.h>
+#include <freeradius-devel/unlang/xlat.h>
+#include <freeradius-devel/util/time.h>
 
 #include "interpret_priv.h"
 #include "module_priv.h"
@@ -1435,6 +1437,9 @@ static xlat_action_t unlang_cancel_never_run(UNUSED TALLOC_CTX *ctx, UNUSED fr_d
 
 /** Allows a request to dynamically alter its own lifetime
  *
+ * %cancel(<timeout>)
+ *
+ * If timeout is 0, then the request is immediately cancelled.
  */
 static xlat_action_t unlang_cancel_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
                                        UNUSED xlat_ctx_t const *xctx,
@@ -1485,7 +1490,9 @@ static xlat_action_t unlang_cancel_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
         *      We call unlang_xlat_yield to keep the interpreter happy
         *      as it expects to see a resume function set.
         */
-       if (!timeout) return unlang_xlat_yield(request, unlang_cancel_never_run, NULL, 0, NULL);
+       if (!timeout || fr_time_delta_eq(timeout->vb_time_delta, fr_time_delta_from_sec(0))) {
+               return unlang_xlat_yield(request, unlang_cancel_never_run, NULL, 0, NULL);
+       }
 
        if (ev_p_og) {
                MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_TIME_DELTA, NULL));