From: Arran Cudbard-Bell Date: Sat, 28 Aug 2021 00:10:26 +0000 (-0500) Subject: Notes on stdin cleanup X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=da5fbe6cd76a7bd7b8ea4528d01cb4d45961cca7;p=thirdparty%2Ffreeradius-server.git Notes on stdin cleanup --- diff --git a/src/lib/server/exec.c b/src/lib/server/exec.c index a2ba8932d06..ac5f7f4474b 100644 --- a/src/lib/server/exec.c +++ b/src/lib/server/exec.c @@ -900,10 +900,6 @@ static void exec_cleanup(fr_exec_state_t *exec) { if (exec->pid) DEBUG3("Cleaning up exec state for pid %u", exec->pid); - /* - * FIXME - Need to do something with stdin? - */ - if (exec->stdout_fd >= 0) { if (fr_event_fd_delete(request->el, exec->stdout_fd, FR_EVENT_FILTER_IO) < 0){ RPERROR("Failed removing stdout handler"); @@ -1154,6 +1150,10 @@ static void exec_stdout_read(UNUSED fr_event_list_t *el, int fd, int flags, void } /** Call an child program, optionally reading it's output + * + * @note If the caller set need_stdin = true, it is the caller's + * responsibility to close exec->std_in and remove it from any event loops + * if this function returns 0 (success). * * @param[in] ctx to allocate events in. * @param[in,out] exec structure holding the state of the external call. @@ -1195,6 +1195,14 @@ int fr_exec_wait_start_io(TALLOC_CTX *ctx, fr_exec_state_t *exec, request_t *req stdout_fd, &exec->stderr_fd, request, cmd, exec->vps) < 0) { RPEDEBUG("Failed executing program"); fail: + /* + * Not done in exec_cleanup as it's + * usually the caller's responsibility. + */ + if (exec->stdin_fd >= 0) { + close(exec->stdin_fd); + exec->stdin_fd = -1; + } exec_cleanup(exec); return -1; }