mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-11 07:34:32 +00:00
Fix bug in the input buffering of messages to/from fishd causing garbled messages
darcs-hash:20061010222113-ac50b-1b6b01ab781ecbadf11a99b501f19a526ae7a7cf.gz
This commit is contained in:
parent
e3e1b34fec
commit
f5916358e5
4 changed files with 29 additions and 17 deletions
|
@ -164,7 +164,6 @@ static void callback( int type, const wchar_t *name, const wchar_t *val )
|
|||
{
|
||||
if( type == BARRIER_REPLY )
|
||||
{
|
||||
debug( 3, L"Got barrier reply" );
|
||||
barrier_reply = 1;
|
||||
}
|
||||
else
|
||||
|
@ -212,6 +211,7 @@ static void reconnect()
|
|||
debug( 3, L"Get new fishd connection" );
|
||||
|
||||
init = 0;
|
||||
env_universal_server.buffer_consumed = env_universal_server.buffer_used = 0;
|
||||
env_universal_server.fd = get_socket(1);
|
||||
init = 1;
|
||||
if( env_universal_server.fd >= 0 )
|
||||
|
@ -226,12 +226,13 @@ void env_universal_init( wchar_t * p,
|
|||
void (*sf)(),
|
||||
void (*cb)( int type, const wchar_t *name, const wchar_t *val ))
|
||||
{
|
||||
debug( 3, L"env_universal_init()" );
|
||||
path=p;
|
||||
user=u;
|
||||
start_fishd=sf;
|
||||
external_callback = cb;
|
||||
|
||||
memset (&env_universal_server, 0, sizeof (connection_t));
|
||||
|
||||
env_universal_server.fd = -1;
|
||||
env_universal_server.killme = 0;
|
||||
env_universal_server.fd = get_socket(1);
|
||||
|
@ -245,7 +246,6 @@ void env_universal_init( wchar_t * p,
|
|||
{
|
||||
env_universal_barrier();
|
||||
}
|
||||
debug( 3, L"end env_universal_init()" );
|
||||
}
|
||||
|
||||
void env_universal_destroy()
|
||||
|
@ -283,8 +283,6 @@ int env_universal_read_all()
|
|||
if( !init)
|
||||
return 0;
|
||||
|
||||
debug( 3, L"env_universal_read_all()" );
|
||||
|
||||
if( env_universal_server.fd == -1 )
|
||||
{
|
||||
reconnect();
|
||||
|
@ -312,7 +310,6 @@ wchar_t *env_universal_get( const wchar_t *name )
|
|||
|
||||
CHECK( name, 0 );
|
||||
|
||||
debug( 3, L"env_universal_get( \"%ls\" )", name );
|
||||
return env_universal_common_get( name );
|
||||
}
|
||||
|
||||
|
@ -323,7 +320,6 @@ int env_universal_get_export( const wchar_t *name )
|
|||
|
||||
CHECK( name, 0 );
|
||||
|
||||
debug( 3, L"env_universal_get_export()" );
|
||||
return env_universal_common_get_export( name );
|
||||
}
|
||||
|
||||
|
@ -367,7 +363,7 @@ void env_universal_barrier()
|
|||
FD_SET( env_universal_server.fd, &fds );
|
||||
select( env_universal_server.fd+1, 0, &fds, 0, 0 );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Wait for barrier reply
|
||||
*/
|
||||
|
|
|
@ -127,7 +127,6 @@ static int get_names_show_unexported;
|
|||
|
||||
void env_universal_common_init( void (*cb)(int type, const wchar_t *key, const wchar_t *val ) )
|
||||
{
|
||||
debug( 3, L"Init env_universal_common" );
|
||||
callback = cb;
|
||||
hash_init( &env_universal_var, &hash_wcs_func, &hash_wcs_cmp );
|
||||
}
|
||||
|
@ -159,6 +158,8 @@ static int read_byte( connection_t *src )
|
|||
|
||||
res = read( src->fd, src->buffer, ENV_UNIVERSAL_BUFFER_SIZE );
|
||||
|
||||
// debug(4, L"Read chunk '%.*s'", res, src->buffer );
|
||||
|
||||
if( res < 0 )
|
||||
{
|
||||
|
||||
|
@ -296,7 +297,7 @@ static int match( const wchar_t *msg, const wchar_t *cmd )
|
|||
static void parse_message( wchar_t *msg,
|
||||
connection_t *src )
|
||||
{
|
||||
debug( 3, L"parse_message( %ls );", msg );
|
||||
// debug( 3, L"parse_message( %ls );", msg );
|
||||
|
||||
if( msg[0] == L'#' )
|
||||
return;
|
||||
|
@ -403,7 +404,16 @@ static int try_send( message_t *msg,
|
|||
L"before write of %d chars to fd %d", strlen(msg->body), fd );
|
||||
|
||||
int res = write( fd, msg->body, strlen(msg->body) );
|
||||
|
||||
|
||||
if( res != -1 )
|
||||
{
|
||||
debug( 4, L"Wrote message '%s'", msg->body );
|
||||
}
|
||||
else
|
||||
{
|
||||
debug( 4, L"Failed to write message '%s'", msg->body );
|
||||
}
|
||||
|
||||
if( res == -1 )
|
||||
{
|
||||
switch( errno )
|
||||
|
@ -412,7 +422,7 @@ static int try_send( message_t *msg,
|
|||
return 0;
|
||||
|
||||
default:
|
||||
debug( 1,
|
||||
debug( 0,
|
||||
L"Error while sending universal variable message to fd %d. Closing connection",
|
||||
fd );
|
||||
wperror( L"write" );
|
||||
|
@ -431,9 +441,9 @@ static int try_send( message_t *msg,
|
|||
|
||||
void try_send_all( connection_t *c )
|
||||
{
|
||||
debug( 3,
|
||||
/* debug( 3,
|
||||
L"Send all updates to connection on fd %d",
|
||||
c->fd );
|
||||
c->fd );*/
|
||||
while( !q_empty( &c->unsent) )
|
||||
{
|
||||
switch( try_send( (message_t *)q_peek( &c->unsent), c->fd ) )
|
||||
|
@ -443,7 +453,7 @@ void try_send_all( connection_t *c )
|
|||
break;
|
||||
|
||||
case 0:
|
||||
debug( 1,
|
||||
debug( 4,
|
||||
L"Socket full, send rest later" );
|
||||
return;
|
||||
|
||||
|
@ -462,6 +472,8 @@ message_t *create_message( int type,
|
|||
|
||||
char *key=0;
|
||||
size_t sz;
|
||||
|
||||
// debug( 4, L"Crete message of type %d", type );
|
||||
|
||||
if( key_in )
|
||||
{
|
||||
|
@ -555,6 +567,9 @@ message_t *create_message( int type,
|
|||
|
||||
if( msg )
|
||||
msg->count=0;
|
||||
|
||||
// debug( 4, L"Message body is '%s'", msg->body );
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
|
|
@ -275,6 +275,7 @@ static int print_max( const wchar_t *str, int max, int has_more )
|
|||
int written = 0;
|
||||
for( i=0; str[i]; i++ )
|
||||
{
|
||||
|
||||
if( written + wcwidth(str[i]) > max )
|
||||
break;
|
||||
if( ( written + wcwidth(str[i]) == max) && (has_more || str[i+1]) )
|
||||
|
@ -1030,7 +1031,7 @@ int main( int argc, char **argv )
|
|||
int is_quoted=0;
|
||||
array_list_t *comp;
|
||||
wchar_t *prefix;
|
||||
|
||||
|
||||
if( argc < 3 )
|
||||
{
|
||||
debug( 0, L"Insufficient arguments" );
|
||||
|
|
2
fishd.c
2
fishd.c
|
@ -604,7 +604,7 @@ int main( int argc, char ** argv )
|
|||
}
|
||||
else
|
||||
{
|
||||
connection_t *new = malloc( sizeof(connection_t));
|
||||
connection_t *new = calloc( 1, sizeof(connection_t));
|
||||
new->fd = child_socket;
|
||||
new->next = conn;
|
||||
q_init( &new->unsent );
|
||||
|
|
Loading…
Reference in a new issue