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:
axel 2006-10-11 08:21:13 +10:00
parent e3e1b34fec
commit f5916358e5
4 changed files with 29 additions and 17 deletions

View file

@ -164,7 +164,6 @@ static void callback( int type, const wchar_t *name, const wchar_t *val )
{ {
if( type == BARRIER_REPLY ) if( type == BARRIER_REPLY )
{ {
debug( 3, L"Got barrier reply" );
barrier_reply = 1; barrier_reply = 1;
} }
else else
@ -212,6 +211,7 @@ static void reconnect()
debug( 3, L"Get new fishd connection" ); debug( 3, L"Get new fishd connection" );
init = 0; init = 0;
env_universal_server.buffer_consumed = env_universal_server.buffer_used = 0;
env_universal_server.fd = get_socket(1); env_universal_server.fd = get_socket(1);
init = 1; init = 1;
if( env_universal_server.fd >= 0 ) if( env_universal_server.fd >= 0 )
@ -226,12 +226,13 @@ void env_universal_init( wchar_t * p,
void (*sf)(), void (*sf)(),
void (*cb)( int type, const wchar_t *name, const wchar_t *val )) void (*cb)( int type, const wchar_t *name, const wchar_t *val ))
{ {
debug( 3, L"env_universal_init()" );
path=p; path=p;
user=u; user=u;
start_fishd=sf; start_fishd=sf;
external_callback = cb; external_callback = cb;
memset (&env_universal_server, 0, sizeof (connection_t));
env_universal_server.fd = -1; env_universal_server.fd = -1;
env_universal_server.killme = 0; env_universal_server.killme = 0;
env_universal_server.fd = get_socket(1); env_universal_server.fd = get_socket(1);
@ -245,7 +246,6 @@ void env_universal_init( wchar_t * p,
{ {
env_universal_barrier(); env_universal_barrier();
} }
debug( 3, L"end env_universal_init()" );
} }
void env_universal_destroy() void env_universal_destroy()
@ -283,8 +283,6 @@ int env_universal_read_all()
if( !init) if( !init)
return 0; return 0;
debug( 3, L"env_universal_read_all()" );
if( env_universal_server.fd == -1 ) if( env_universal_server.fd == -1 )
{ {
reconnect(); reconnect();
@ -312,7 +310,6 @@ wchar_t *env_universal_get( const wchar_t *name )
CHECK( name, 0 ); CHECK( name, 0 );
debug( 3, L"env_universal_get( \"%ls\" )", name );
return env_universal_common_get( name ); return env_universal_common_get( name );
} }
@ -323,7 +320,6 @@ int env_universal_get_export( const wchar_t *name )
CHECK( name, 0 ); CHECK( name, 0 );
debug( 3, L"env_universal_get_export()" );
return env_universal_common_get_export( name ); return env_universal_common_get_export( name );
} }
@ -367,7 +363,7 @@ void env_universal_barrier()
FD_SET( env_universal_server.fd, &fds ); FD_SET( env_universal_server.fd, &fds );
select( env_universal_server.fd+1, 0, &fds, 0, 0 ); select( env_universal_server.fd+1, 0, &fds, 0, 0 );
} }
/* /*
Wait for barrier reply Wait for barrier reply
*/ */

View file

@ -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 ) ) 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; callback = cb;
hash_init( &env_universal_var, &hash_wcs_func, &hash_wcs_cmp ); 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 ); res = read( src->fd, src->buffer, ENV_UNIVERSAL_BUFFER_SIZE );
// debug(4, L"Read chunk '%.*s'", res, src->buffer );
if( res < 0 ) 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, static void parse_message( wchar_t *msg,
connection_t *src ) connection_t *src )
{ {
debug( 3, L"parse_message( %ls );", msg ); // debug( 3, L"parse_message( %ls );", msg );
if( msg[0] == L'#' ) if( msg[0] == L'#' )
return; 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 ); L"before write of %d chars to fd %d", strlen(msg->body), fd );
int res = write( fd, msg->body, strlen(msg->body) ); 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 ) if( res == -1 )
{ {
switch( errno ) switch( errno )
@ -412,7 +422,7 @@ static int try_send( message_t *msg,
return 0; return 0;
default: default:
debug( 1, debug( 0,
L"Error while sending universal variable message to fd %d. Closing connection", L"Error while sending universal variable message to fd %d. Closing connection",
fd ); fd );
wperror( L"write" ); wperror( L"write" );
@ -431,9 +441,9 @@ static int try_send( message_t *msg,
void try_send_all( connection_t *c ) void try_send_all( connection_t *c )
{ {
debug( 3, /* debug( 3,
L"Send all updates to connection on fd %d", L"Send all updates to connection on fd %d",
c->fd ); c->fd );*/
while( !q_empty( &c->unsent) ) while( !q_empty( &c->unsent) )
{ {
switch( try_send( (message_t *)q_peek( &c->unsent), c->fd ) ) switch( try_send( (message_t *)q_peek( &c->unsent), c->fd ) )
@ -443,7 +453,7 @@ void try_send_all( connection_t *c )
break; break;
case 0: case 0:
debug( 1, debug( 4,
L"Socket full, send rest later" ); L"Socket full, send rest later" );
return; return;
@ -462,6 +472,8 @@ message_t *create_message( int type,
char *key=0; char *key=0;
size_t sz; size_t sz;
// debug( 4, L"Crete message of type %d", type );
if( key_in ) if( key_in )
{ {
@ -555,6 +567,9 @@ message_t *create_message( int type,
if( msg ) if( msg )
msg->count=0; msg->count=0;
// debug( 4, L"Message body is '%s'", msg->body );
return msg; return msg;
} }

View file

@ -275,6 +275,7 @@ static int print_max( const wchar_t *str, int max, int has_more )
int written = 0; int written = 0;
for( i=0; str[i]; i++ ) for( i=0; str[i]; i++ )
{ {
if( written + wcwidth(str[i]) > max ) if( written + wcwidth(str[i]) > max )
break; break;
if( ( written + wcwidth(str[i]) == max) && (has_more || str[i+1]) ) 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; int is_quoted=0;
array_list_t *comp; array_list_t *comp;
wchar_t *prefix; wchar_t *prefix;
if( argc < 3 ) if( argc < 3 )
{ {
debug( 0, L"Insufficient arguments" ); debug( 0, L"Insufficient arguments" );

View file

@ -604,7 +604,7 @@ int main( int argc, char ** argv )
} }
else else
{ {
connection_t *new = malloc( sizeof(connection_t)); connection_t *new = calloc( 1, sizeof(connection_t));
new->fd = child_socket; new->fd = child_socket;
new->next = conn; new->next = conn;
q_init( &new->unsent ); q_init( &new->unsent );