]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clean up and normalize error messages
authorAlan T. DeKok <aland@freeradius.org>
Fri, 8 Dec 2023 13:32:44 +0000 (08:32 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 8 Dec 2023 13:32:44 +0000 (08:32 -0500)
src/lib/server/exec.c
src/lib/server/exec.h
src/modules/rlm_exec/rlm_exec.c
src/tests/modules/exec/sync.unlang

index 5a8f8fb985dada6fe75bb122f71624ab7805d1ea..65891ade16080eba4feb435052f3342cc3434e28 100644 (file)
@@ -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;
                }
index 4c0b82cd86519a9eed163f9f3631b5a40d4b6865..7f5335e8e504121f52f0f1d4909d63700993ebb8 100644 (file)
@@ -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
 
index c77fcf0559ade14121a456e14d89eb9530b70e54..d1baf1c68f9ce5012b157f1ac9e82079fcc7102f 100644 (file)
@@ -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.
index 341842d5f12be6b7ecd2ce7bb97018517b91335e..3fd6167c69a6c87b985b34dbe869c9693392c042 100644 (file)
@@ -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
 }