diff --git a/src/ChangeLog b/src/ChangeLog index cc3ae89f1..0b5d7d2fc 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2002-07-29 Pavel Roskin + * subshell.c (feed_subshell): Reading 0 bytes in a channel with + FD_ISSET being set is a sign of something being wrong - exit + immediately. Observed when mc is run under su in xterm and + xterm is closed while the subshell is running. + Reported by Vlad Harchev + * color.h: Replace PORT_COLOR macro with BEST_COLOR, which uses MY_COLOR_PAIR. diff --git a/src/subshell.c b/src/subshell.c index f66c524b6..5e65dd7ff 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -990,22 +990,20 @@ static int feed_subshell (int how, int fail_on_error) /* for (i=0; i<5; ++i) * FIXME -- experimental */ { bytes = read (subshell_pty, pty_buffer, pty_buffer_size); - /* Patch from viro@math.psu.edu - * add by MichaelBramer (Debian MC-Maintainer */ + + /* The subshell has died */ if (bytes == -1 && errno == EIO && !subshell_alive) - { return FALSE; - } - if (bytes == -1) - /* end from the patch */ + + if (bytes <= 0) { tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode); perror ("\n"__FILE__": read (subshell_pty...)"); exit (1); } - if (bytes > 0) - if (how == VISIBLY) - write (STDOUT_FILENO, pty_buffer, bytes); + + if (how == VISIBLY) + write (STDOUT_FILENO, pty_buffer, bytes); } /* }}} */ @@ -1015,14 +1013,14 @@ static int feed_subshell (int how, int fail_on_error) { bytes = read (subshell_pipe[READ], subshell_cwd, MC_MAXPATHLEN+1); - if (bytes == -1) + if (bytes <= 0) { tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode); perror ("\n"__FILE__": read (subshell_pipe[READ]...)"); exit (1); } - if (bytes >= 1) - subshell_cwd[bytes-1] = 0; /* Squash the final '\n' */ + + subshell_cwd[bytes-1] = 0; /* Squash the final '\n' */ synchronize (); @@ -1041,7 +1039,7 @@ static int feed_subshell (int how, int fail_on_error) { bytes = read (STDIN_FILENO, pty_buffer, pty_buffer_size); - if (bytes == -1) + if (bytes <= 0) { tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode); perror ("\n"__FILE__": read (STDIN_FILENO, pty_buffer...)");