Ticket #2008: 0001-Ticket-2008-reimplemented-pty_buffer-as-static-buf.patch

File 0001-Ticket-2008-reimplemented-pty_buffer-as-static-buf.patch, 2.9 KB (added by andrew_b, 13 years ago)
  • src/subshell.c

    From 06ed7da041cee4584f0315be85d9cb55834aeffb Mon Sep 17 00:00:00 2001
    From: Andrew Borodin <aborodin@vmail.ru>
    Date: Sun, 7 Feb 2010 11:55:36 +0300
    Subject: [PATCH] Ticket #2008: reimplemented pty_buffer as static buffer.
    
    Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
    ---
     src/subshell.c |   21 +++++++--------------
     1 files changed, 7 insertions(+), 14 deletions(-)
    
    diff --git a/src/subshell.c b/src/subshell.c
    index a23b106..1b4ff8c 100644
    a b char *subshell_prompt = NULL; 
    121121/* Used by the child process to indicate failure to start the subshell */ 
    122122#define FORK_FAILURE 69  /* Arbitrary */ 
    123123 
    124 /* Initial length of the buffer for all I/O with the subshell */ 
    125 #define INITIAL_PTY_BUFFER_SIZE 100  /* Arbitrary; but keep it >= 80 */ 
     124/* Length of the buffer for all I/O with the subshell */ 
     125#define PTY_BUFFER_SIZE BUF_SMALL  /* Arbitrary; but keep it >= 80 */ 
    126126 
    127127/* For pipes */ 
    128128enum {READ=0, WRITE=1}; 
    129129 
    130 static char *pty_buffer;        /* For reading/writing on the subshell's pty */ 
    131 static int pty_buffer_size;     /* The buffer grows as needed */ 
     130static char pty_buffer[PTY_BUFFER_SIZE] = "\0"; /* For reading/writing on the subshell's pty */ 
    132131static int subshell_pipe[2];    /* To pass CWD info from the subshell to MC */ 
    133132static pid_t subshell_pid = 1;  /* The subshell's process ID */ 
    134133static char subshell_cwd[MC_MAXPATHLEN+1];  /* One extra char for final '\n' */ 
    init_subshell (void) 
    423422            return; 
    424423        } 
    425424 
    426         /* Initialise the pty's I/O buffer */ 
    427  
    428         pty_buffer_size = INITIAL_PTY_BUFFER_SIZE; 
    429         pty_buffer = g_malloc (pty_buffer_size); 
    430  
    431425        /* Create a pipe for receiving the subshell's CWD */ 
    432426 
    433427        if (subshell_type == TCSH) { 
    read_subshell_prompt (void) 
    625619            } 
    626620        } 
    627621 
    628         bytes = read (subshell_pty, pty_buffer, pty_buffer_size); 
     622        bytes = read (subshell_pty, pty_buffer, sizeof (pty_buffer)); 
    629623 
    630624        /* Extract the prompt from the shell output */ 
    631625 
    exit_subshell (void) 
    693687        } 
    694688 
    695689        g_free (subshell_prompt); 
    696         g_free (pty_buffer); 
    697690        subshell_prompt = NULL; 
    698         pty_buffer = NULL; 
     691        pty_buffer[0] = '\0'; 
    699692    } 
    700693 
    701694    return subshell_quit; 
    feed_subshell (int how, int fail_on_error) 
    979972               randomly, because of an apparent Linux bug.  Investigate. */ 
    980973            /* for (i=0; i<5; ++i)  * FIXME -- experimental */ 
    981974        { 
    982             bytes = read (subshell_pty, pty_buffer, pty_buffer_size); 
     975            bytes = read (subshell_pty, pty_buffer, sizeof (pty_buffer)); 
    983976 
    984977            /* The subshell has died */ 
    985978            if (bytes == -1 && errno == EIO && !subshell_alive) 
    feed_subshell (int how, int fail_on_error) 
    10241017        else if (FD_ISSET (STDIN_FILENO, &read_set)) 
    10251018            /* Read from stdin, write to the subshell */ 
    10261019        { 
    1027             bytes = read (STDIN_FILENO, pty_buffer, pty_buffer_size); 
     1020            bytes = read (STDIN_FILENO, pty_buffer, sizeof (pty_buffer)); 
    10281021            if (bytes <= 0) { 
    10291022                tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode); 
    10301023                fprintf (stderr,