Skip to content

Commit ea410cb

Browse files
committed
clean up FDs and PID in all situations
and don't complain on cleanup if the program exited cleanly.
1 parent 7b46210 commit ea410cb

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/lib/server/exec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,8 @@ void fr_exec_oneshot_cleanup(fr_exec_state_t *exec, int signal)
683683

684684
if (exec->pid >= 0) {
685685
RDEBUG3("Cleaning up exec state for PID %u", exec->pid);
686-
} else {
686+
687+
} else if (exec->failed != FR_EXEC_FAIL_NONE) {
687688
RDEBUG3("Cleaning up failed exec");
688689
}
689690

src/modules/rlm_exec/rlm_exec.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static xlat_action_t exec_xlat_oneshot_wait_resume(TALLOC_CTX *ctx, fr_dcursor_t
8787
fr_exec_state_t *exec = talloc_get_type_abort(xctx->rctx, fr_exec_state_t);
8888
fr_value_box_t *vb;
8989

90-
if (exec->failed == FR_EXEC_FAIL_TIMEOUT) {
90+
if (exec->failed != FR_EXEC_FAIL_NONE) {
9191
RPEDEBUG("Execution of external program failed");
9292
return XLAT_ACTION_FAIL;
9393
}
@@ -127,6 +127,12 @@ static xlat_arg_parser_t const exec_xlat_args[] = {
127127
XLAT_ARG_PARSER_TERMINATOR
128128
};
129129

130+
static int _exec_free(fr_exec_state_t *exec)
131+
{
132+
fr_exec_oneshot_cleanup(exec, SIGKILL);
133+
return 0;
134+
}
135+
130136
/** Exec programs from an xlat
131137
*
132138
* Example:
@@ -174,6 +180,7 @@ static xlat_action_t exec_xlat_oneshot(TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out
174180
talloc_free(exec);
175181
return XLAT_ACTION_FAIL;
176182
}
183+
talloc_set_destructor(exec, _exec_free);
177184

178185
return unlang_xlat_yield(request, exec_xlat_oneshot_wait_resume, NULL, 0, exec);
179186
}

0 commit comments

Comments
 (0)