From: Alan T. DeKok Date: Fri, 8 Dec 2023 13:32:44 +0000 (-0500) Subject: clean up and normalize error messages X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae90759208eb0b854e12d00b197cd00a1384b048;p=thirdparty%2Ffreeradius-server.git clean up and normalize error messages --- diff --git a/src/lib/server/exec.c b/src/lib/server/exec.c index 5a8f8fb985d..65891ade160 100644 --- a/src/lib/server/exec.c +++ b/src/lib/server/exec.c @@ -842,11 +842,12 @@ static void exec_timeout(UNUSED fr_event_list_t *el, UNUSED fr_time_t now, void fr_exec_state_t *exec = uctx; /* may not be talloced */ if (exec->stdout_fd < 0) { - fr_strerror_const("Timeout waiting for program to exit - killing it and failing the request"); + fr_strerror_const("Timeout waiting for program to exit"); } else { - fr_strerror_const("Timeout running program - killing it and failing the request"); + fr_strerror_const("Timeout running program"); } - exec->failed = true; + + exec->failed = FR_EXEC_FAIL_TIMEOUT; fr_exec_oneshot_cleanup(exec, SIGKILL); unlang_interpret_mark_runnable(exec->request); @@ -876,7 +877,7 @@ static void exec_stdout_read(UNUSED fr_event_list_t *el, int fd, int flags, void REDEBUG("Too much output from program - killing it and failing the request"); error: - exec->failed = true; + exec->failed = FR_EXEC_FAIL_TOO_MUCH_DATA; fr_exec_oneshot_cleanup(exec, SIGKILL); break; } diff --git a/src/lib/server/exec.h b/src/lib/server/exec.h index 4c0b82cd865..7f5335e8e50 100644 --- a/src/lib/server/exec.h +++ b/src/lib/server/exec.h @@ -44,6 +44,12 @@ extern "C" { extern "C" { #endif +typedef enum { + FR_EXEC_FAIL_NONE = 0, + FR_EXEC_FAIL_TOO_MUCH_DATA, + FR_EXEC_FAIL_TIMEOUT, +} fr_exec_fail_t; + typedef struct { fr_sbuff_t stdout_buff; //!< Expandable buffer to store process output. fr_sbuff_uctx_talloc_t stdout_tctx; //!< sbuff talloc ctx data. @@ -65,7 +71,7 @@ typedef struct { fr_event_timer_t const *ev; //!< for timing out the child fr_event_pid_t const *ev_pid; //!< for cleaning up the process - bool failed; //!< due to exec timeout or buffer overflow + fr_exec_fail_t failed; //!< what kind of failure int status; //!< return code of the program diff --git a/src/modules/rlm_exec/rlm_exec.c b/src/modules/rlm_exec/rlm_exec.c index c77fcf0559a..d1baf1c68f9 100644 --- a/src/modules/rlm_exec/rlm_exec.c +++ b/src/modules/rlm_exec/rlm_exec.c @@ -84,6 +84,11 @@ static xlat_action_t exec_xlat_oneshot_wait_resume(TALLOC_CTX *ctx, fr_dcursor_t fr_exec_state_t *exec = talloc_get_type_abort(xctx->rctx, fr_exec_state_t); fr_value_box_t *vb; + if (exec->failed == FR_EXEC_FAIL_TIMEOUT) { + RPEDEBUG("Execution of external program failed"); + return XLAT_ACTION_FAIL; + } + /* * Allow a return code of 3 as success to match the behaviour of * inline module calls. diff --git a/src/tests/modules/exec/sync.unlang b/src/tests/modules/exec/sync.unlang index 341842d5f12..3fd6167c69a 100644 --- a/src/tests/modules/exec/sync.unlang +++ b/src/tests/modules/exec/sync.unlang @@ -12,7 +12,7 @@ if (&Tmp-String-0 != 'hello') { &request -= &Tmp-String-0 &Tmp-String-0 := "%(exec_sync:/bin/sleep 10)" -if (&Module-Failure-Message[*] != "Timeout running program - killing it and failing the request") { +if (&Module-Failure-Message[*] != "Execution of external program failed: Timeout running program") { test_fail }