From e65b0f19865adbd8d97145584be13a1463039334 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Fri, 26 Jun 2009 13:24:10 +0300 Subject: [PATCH 1/2] viewer: Ticket: Viewer(F3) hangups at '.patch' viewing As stderr closes before process shutdown we get hangup trying to read last data from stderr. Try to read at least something before closing stderr. Signed-off-by: Sergei Trofimovich --- src/utilunix.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/utilunix.c b/src/utilunix.c index acaa7678e..8c314ac6c 100644 --- a/src/utilunix.c +++ b/src/utilunix.c @@ -355,6 +355,27 @@ void open_error_pipe (void) close (error_pipe[0]); error_pipe[0] = -1; } + else + { + /* + * Settng stderr in nonblocking mode as we close it earlier, than + * program stops. We try to read some error at program startup, + * but we should not block on it. + * + * TODO: make piped stdin/stderr poll()/select()able to get rid + * of following hack. + */ + int fd_flags; + fd_flags = fcntl (error_pipe[0], F_GETFL, NULL); + if (fd_flags != -1) + { + fd_flags |= O_NONBLOCK; + if (fcntl(error_pipe[0], F_SETFL, fd_flags) == -1) + { + /* TODO: handle it somehow */ + } + } + } /* we never write there */ close (error_pipe[1]); error_pipe[1] = -1; From c07b5efe455f32a0bf3cf090b784c7c2993a28cf Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Fri, 26 Jun 2009 13:39:47 +0300 Subject: [PATCH 2/2] close_error_pipe: return value instead of garbage Signed-off-by: Sergei Trofimovich --- src/utilunix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilunix.c b/src/utilunix.c index 8c314ac6c..0dade587a 100644 --- a/src/utilunix.c +++ b/src/utilunix.c @@ -395,7 +395,7 @@ close_error_pipe (int error, const char *text) /* already closed */ if (error_pipe[0] == -1) - return; + return 0; if (error) title = MSG_ERROR;