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; |
121 | 121 | /* Used by the child process to indicate failure to start the subshell */ |
122 | 122 | #define FORK_FAILURE 69 /* Arbitrary */ |
123 | 123 | |
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 */ |
126 | 126 | |
127 | 127 | /* For pipes */ |
128 | 128 | enum {READ=0, WRITE=1}; |
129 | 129 | |
130 | | static char *pty_buffer; /* For reading/writing on the subshell's pty */ |
131 | | static int pty_buffer_size; /* The buffer grows as needed */ |
| 130 | static char pty_buffer[PTY_BUFFER_SIZE] = "\0"; /* For reading/writing on the subshell's pty */ |
132 | 131 | static int subshell_pipe[2]; /* To pass CWD info from the subshell to MC */ |
133 | 132 | static pid_t subshell_pid = 1; /* The subshell's process ID */ |
134 | 133 | static char subshell_cwd[MC_MAXPATHLEN+1]; /* One extra char for final '\n' */ |
… |
… |
init_subshell (void) |
423 | 422 | return; |
424 | 423 | } |
425 | 424 | |
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 | | |
431 | 425 | /* Create a pipe for receiving the subshell's CWD */ |
432 | 426 | |
433 | 427 | if (subshell_type == TCSH) { |
… |
… |
read_subshell_prompt (void) |
625 | 619 | } |
626 | 620 | } |
627 | 621 | |
628 | | bytes = read (subshell_pty, pty_buffer, pty_buffer_size); |
| 622 | bytes = read (subshell_pty, pty_buffer, sizeof (pty_buffer)); |
629 | 623 | |
630 | 624 | /* Extract the prompt from the shell output */ |
631 | 625 | |
… |
… |
exit_subshell (void) |
693 | 687 | } |
694 | 688 | |
695 | 689 | g_free (subshell_prompt); |
696 | | g_free (pty_buffer); |
697 | 690 | subshell_prompt = NULL; |
698 | | pty_buffer = NULL; |
| 691 | pty_buffer[0] = '\0'; |
699 | 692 | } |
700 | 693 | |
701 | 694 | return subshell_quit; |
… |
… |
feed_subshell (int how, int fail_on_error) |
979 | 972 | randomly, because of an apparent Linux bug. Investigate. */ |
980 | 973 | /* for (i=0; i<5; ++i) * FIXME -- experimental */ |
981 | 974 | { |
982 | | bytes = read (subshell_pty, pty_buffer, pty_buffer_size); |
| 975 | bytes = read (subshell_pty, pty_buffer, sizeof (pty_buffer)); |
983 | 976 | |
984 | 977 | /* The subshell has died */ |
985 | 978 | if (bytes == -1 && errno == EIO && !subshell_alive) |
… |
… |
feed_subshell (int how, int fail_on_error) |
1024 | 1017 | else if (FD_ISSET (STDIN_FILENO, &read_set)) |
1025 | 1018 | /* Read from stdin, write to the subshell */ |
1026 | 1019 | { |
1027 | | bytes = read (STDIN_FILENO, pty_buffer, pty_buffer_size); |
| 1020 | bytes = read (STDIN_FILENO, pty_buffer, sizeof (pty_buffer)); |
1028 | 1021 | if (bytes <= 0) { |
1029 | 1022 | tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode); |
1030 | 1023 | fprintf (stderr, |