]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Notes on stdin cleanup
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 28 Aug 2021 00:10:26 +0000 (19:10 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 28 Aug 2021 00:10:26 +0000 (19:10 -0500)
src/lib/server/exec.c

index a2ba8932d06f3807c3ef9a23125e016af9f2d56c..ac5f7f4474b61e20e8504643ff95a0ca5febb71a 100644 (file)
@@ -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;
        }