diff --git a/src/utilunix.c b/src/utilunix.c index 38fe8e690..acaa7678e 100644 --- a/src/utilunix.c +++ b/src/utilunix.c @@ -351,10 +351,13 @@ void open_error_pipe (void) old_error = dup (2); if(old_error < 0 || close(2) || dup (error_pipe[1]) != 2){ message (D_NORMAL, _("Warning"), _(" Dup failed ")); + close (error_pipe[0]); - close (error_pipe[1]); + error_pipe[0] = -1; } + /* we never write there */ close (error_pipe[1]); + error_pipe[1] = -1; } /* @@ -369,6 +372,10 @@ close_error_pipe (int error, const char *text) char msg[MAX_PIPE_SIZE]; int len = 0; + /* already closed */ + if (error_pipe[0] == -1) + return; + if (error) title = MSG_ERROR; else @@ -382,6 +389,7 @@ close_error_pipe (int error, const char *text) if (len >= 0) msg[len] = 0; close (error_pipe[0]); + error_pipe[0] = -1; } if (error < 0) return 0; /* Just ignore error message */ diff --git a/src/view.c b/src/view.c index 07deaf867..4a7873663 100644 --- a/src/view.c +++ b/src/view.c @@ -1936,6 +1936,15 @@ view_load_command_output (WView *view, const char *command) if (!close_error_pipe (view_is_in_panel (view) ? -1 : D_ERROR, NULL)) view_show_error (view, _("Empty output from child filter")); return FALSE; + } else { + /* + * At least something was read correctly. Close stderr and let + * program die if it will try to write something there. + * + * Ideally stderr should be read asynchronously to prevent programs + * from blocking (poll/select multiplexor). + */ + close_error_pipe (D_NORMAL, NULL); } return TRUE; }