aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-03-10 23:38:09 +1000
committerGravatar axel <axel@liljencrantz.se>2006-03-10 23:38:09 +1000
commit32b531667aa1e7f085b8316ffd5c8df7f6b3987c (patch)
tree154a49403412d633d396390b447dbd97001f51dd
parentc47dae77a4a6c4789fc730d471502bcebdcb8c76 (diff)
Fix bug that causing terminal corruption if a job is put under job control before running in interactive mode. This is fixed by doing more inits at startup (but only slightly more)
darcs-hash:20060310133809-ac50b-d31cd7bab1a3a58de2833f73735817a3d0b3ed7d.gz
-rw-r--r--builtin.c5
-rw-r--r--input.c12
-rw-r--r--input.h1
-rw-r--r--input_common.c8
-rw-r--r--main.c9
-rw-r--r--proc.c11
-rw-r--r--reader.c57
7 files changed, 50 insertions, 53 deletions
diff --git a/builtin.c b/builtin.c
index 62f7911f..a5528121 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2017,10 +2017,10 @@ static int builtin_source( wchar_t ** argv )
parser_push_block( SOURCE );
reader_push_current_filename( fn_intern );
-
current_block->param1.source_dest = fn_intern;
parse_util_set_argv( argv+2);
+
res = reader_read( fd );
parser_pop_block();
@@ -2029,8 +2029,7 @@ static int builtin_source( wchar_t ** argv )
sb_printf( sb_err,
_( L"%ls: Error while reading file '%ls'\n" ),
argv[0],
- argv[1]
- );
+ argv[1] );
}
/*
diff --git a/input.c b/input.c
index 9c81fb80..27b7b98e 100644
--- a/input.c
+++ b/input.c
@@ -228,6 +228,8 @@ static int inputrc_block_count=0;
*/
static int inputrc_error = 0;
+static int is_init = 0;
+
wchar_t input_get_code( wchar_t *name )
{
@@ -1346,6 +1348,11 @@ int input_init()
{
wchar_t *fn;
+ if( is_init )
+ return 1;
+
+ is_init = 1;
+
input_common_init( &interrupt_handler );
if( setupterm( 0, STDOUT_FILENO, 0) == ERR )
@@ -1424,6 +1431,11 @@ static void destroy_mapping( const void *key, const void *val )
void input_destroy()
{
+ if( !is_init )
+ return;
+
+ is_init=0;
+
input_common_destroy();
hash_foreach( &all_mappings, &destroy_mapping );
diff --git a/input.h b/input.h
index 7092e3c3..e5a375bb 100644
--- a/input.h
+++ b/input.h
@@ -9,6 +9,7 @@ inputrc information for key bindings.
#define FISH_INPUT_H
#include <wchar.h>
+#include "input_common.h"
/**
Key codes for inputrc-style keyboard functions that are passed on
diff --git a/input_common.c b/input_common.c
index a7abc800..0955e03b 100644
--- a/input_common.c
+++ b/input_common.c
@@ -89,16 +89,9 @@ static wint_t readb()
case EINTR:
case EAGAIN:
{
-// wperror( L"select" );
if( interrupt_handler )
{
int res = interrupt_handler();
-
-/* debug( 0,
- L"interrupt, %d is %ls",
- res,
- (res==R_NULL?L"good": L"Bad") );
-*/
if( res )
return res;
}
@@ -143,6 +136,7 @@ static wint_t readb()
return arr[0];
}
+
wchar_t input_common_readch( int timed )
{
if( lookahead_count == 0 )
diff --git a/main.c b/main.c
index 8e9dac8e..9e0b90bc 100644
--- a/main.c
+++ b/main.c
@@ -62,6 +62,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "translate.h"
#include "halloc_util.h"
+
/**
Parse init files
*/
@@ -69,7 +70,7 @@ static int read_init()
{
char cwd[4096];
wchar_t *wcwd;
-
+
if( !getcwd( cwd, 4096 ) )
{
wperror( L"getcwd" );
@@ -77,11 +78,11 @@ static int read_init()
}
env_set( L"__fish_help_dir", DOCDIR, 0);
-
+
eval( L"builtin cd " DATADIR L"/fish 2>/dev/null; . fish 2>/dev/null", 0, TOP );
eval( L"builtin cd " SYSCONFDIR L" 2>/dev/null; . fish 2>/dev/null", 0, TOP );
eval( L"builtin cd 2>/dev/null;. .fish 2>/dev/null", 0, TOP );
-
+
if( chdir( cwd ) == -1 )
{
// fwprintf( stderr, L"Invalid directory: %s\n", cwd );
@@ -248,7 +249,7 @@ int main( int argc, char **argv )
env_init();
complete_init();
reader_init();
-
+
if( read_init() )
{
if( cmd != 0 )
diff --git a/proc.c b/proc.c
index 5ea4f7e3..431d8e2c 100644
--- a/proc.c
+++ b/proc.c
@@ -192,7 +192,7 @@ job_t *job_create()
res->job_control = (job_control_mode==JOB_CONTROL_ALL) ||
((job_control_mode == JOB_CONTROL_INTERACTIVE) && (is_interactive));
-
+
// if( res->job_id > 2 )
// fwprintf( stderr, L"Create job %d\n", res->job_id );
return res;
@@ -813,8 +813,7 @@ static void read_try( job_t *j )
else
{
b_append( buff->param2.out_buffer, b, l );
- }
-
+ }
}
}
}
@@ -829,14 +828,14 @@ void job_continue (job_t *j, int cont)
j->next = first_job;
first_job = j;
j->notified = 0;
-
+
debug( 4,
- L"Continue on job %d (%ls), %ls, %ls",
+ L"Continue job %d (%ls), %ls, %ls",
j->job_id,
j->command,
job_is_completed( j )?L"COMPLETED":L"UNCOMPLETED",
is_interactive?L"INTERACTIVE":L"NON-INTERACTIVE" );
-
+
if( !job_is_completed( j ) )
{
if( j->terminal && j->fg )
diff --git a/reader.c b/reader.c
index d654b9f7..4270c8e6 100644
--- a/reader.c
+++ b/reader.c
@@ -269,12 +269,6 @@ static struct stat prev_buff_1, prev_buff_2, post_buff_1, post_buff_2;
*/
static array_list_t prompt_list;
-/**
- Stores the previous termios mode so we can reset the modes when
- we execute programs and when the shell exits.
-*/
-static struct termios saved_modes;
-
/**
Store the pid of the parent process, so the exit function knows whether it should reset the terminal or not.
@@ -295,6 +289,12 @@ static struct termios old_modes;
Prototypes for a bunch of functions defined later on.
*/
+/**
+ Stores the previous termios mode so we can reset the modes when
+ we execute programs and when the shell exits.
+*/
+static struct termios saved_modes;
+
static void reader_save_status();
static void reader_check_status();
static void reader_super_highlight_me_plenty( wchar_t * buff, int *color, int pos, array_list_t *error );
@@ -841,6 +841,16 @@ static void write_cmdline()
void reader_init()
{
+ tcgetattr(0,&shell_modes); /* get the current terminal modes */
+ memcpy( &saved_modes,
+ &shell_modes,
+ sizeof(saved_modes)); /* save a copy so we can reset the terminal later */
+
+ shell_modes.c_lflag &= ~ICANON; /* turn off canonical mode */
+ shell_modes.c_lflag &= ~ECHO; /* turn off echo mode */
+ shell_modes.c_cc[VMIN]=1;
+ shell_modes.c_cc[VTIME]=0;
+
al_init( &current_filename);
}
@@ -854,6 +864,8 @@ void reader_destroy()
free( readline_buffer );
readline_buffer=0;
}
+ tcsetattr(0, TCSANOW, &saved_modes);
+
}
@@ -1571,18 +1583,6 @@ static int handle_completions( array_list_t *comp )
}
}
-/**
- Reset the terminal. This function is placed in the list of
- functions to call when exiting by using the atexit function. It
- checks whether it is the original parent process that is exiting
- and not a subshell, and if it is the parent, it restores the
- terminal.
-*/
-static void exit_func()
-{
- if( getpid() == original_pid )
- tcsetattr(0, TCSANOW, &saved_modes);
-}
/**
Initialize data for interactive use
@@ -1635,16 +1635,6 @@ static void reader_interactive_init()
common_handle_winch(0);
- tcgetattr(0,&shell_modes); /* get the current terminal modes */
- memcpy( &saved_modes,
- &shell_modes,
- sizeof(saved_modes)); /* save a copy so we can reset the terminal later */
-
- shell_modes.c_lflag &= ~ICANON; /* turn off canonical mode */
- shell_modes.c_lflag &= ~ECHO; /* turn off echo mode */
- shell_modes.c_cc[VMIN]=1;
- shell_modes.c_cc[VTIME]=0;
-
if( tcsetattr(0,TCSANOW,&shell_modes)) /* set the new modes */
{
wperror(L"tcsetattr");
@@ -1657,9 +1647,6 @@ static void reader_interactive_init()
*/
original_pid = getpid();
- if( atexit( &exit_func ) )
- debug( 1, _( L"Could not set exit function" ) );
-
env_set( L"_", L"fish", ENV_GLOBAL );
}
@@ -2799,7 +2786,11 @@ wchar_t *reader_readline()
if( (!wchar_private(c)) && (c>31) && (c != 127) )
insert_char( c );
else
- debug( 0, _( L"Unknown keybinding %d" ), c );
+ {
+ // Carriage returns happen. We ignore them
+ if( c != 13 )
+ debug( 0, _( L"Unknown keybinding %d" ), c );
+ }
break;
}
@@ -2950,7 +2941,7 @@ int reader_read( int fd )
*/
proc_push_interactive( ((fd == 0) && isatty(STDIN_FILENO)));
-
+
res= is_interactive?read_i():read_ni( fd );
/*