Ticket #424: 0001-viewer-Ticket-410-certain-binary-treated-as-roff.patch

File 0001-viewer-Ticket-410-certain-binary-treated-as-roff.patch, 1.5 KB (added by slyfox, 10 years ago)

rfc patch. may subtly break something

  • src/view.c

    From 9bf43d4debdde213427d37006b28d82647df1175 Mon Sep 17 00:00:00 2001
    From: Sergei Trofimovich <slyfox@inbox.ru>
    Date: Sat, 20 Jun 2009 16:29:44 +0300
    Subject: [PATCH] viewer: Ticket: #410  certain binary treated-as-roff files cause viewer hangup
    
    Hangup state:
    viewer executes program an checks whether it emits data from stdout
    or stderr and receives them via UNIX pipes. Viewer reads stdout
    synchronously (fread). Inferior program tries to write large chunk
    to stderr when viewer is blocked on stdout read. We get a deadlock:
    
    * viewer is blocked reading from empty nonclosed stdout
    * inferior app is blocked by full stderr pipe
    
    To prevent this we close stderr right after first read byte from stdout.
    
    Signed-off-by: Sergei Trofimovich <slyfox@inbox.ru>
    ---
     src/view.c |    9 +++++++++
     1 files changed, 9 insertions(+), 0 deletions(-)
    
    diff --git a/src/view.c b/src/view.c
    index 59ef83d..53db50f 100644
    a b view_load_command_output (WView *view, const char *command) 
    19361936        if (!close_error_pipe (view_is_in_panel (view) ? -1 : D_ERROR, NULL)) 
    19371937            view_show_error (view, _("Empty output from child filter")); 
    19381938        return FALSE; 
     1939    } else { 
     1940        /* 
     1941         * At least something was read correctly. Close stderr and let 
     1942         * program die if it will try to write something there. 
     1943         * 
     1944         * Ideally stderr should be read asynchronously to prevent programs 
     1945         * from blocking (poll/select multiplexor). 
     1946         */ 
     1947        close_error_pipe (D_NORMAL, NULL); 
    19391948    } 
    19401949    return TRUE; 
    19411950}