diff --git a/env_universal.c b/env_universal.c index 1e1dbf872..44439caaa 100644 --- a/env_universal.c +++ b/env_universal.c @@ -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 */ diff --git a/env_universal_common.c b/env_universal_common.c index cf8dad1ea..cb95254a8 100644 --- a/env_universal_common.c +++ b/env_universal_common.c @@ -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; } diff --git a/fish_pager.c b/fish_pager.c index 855fd14ba..026e04297 100644 --- a/fish_pager.c +++ b/fish_pager.c @@ -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" ); diff --git a/fishd.c b/fishd.c index 4c6b6b312..eebc778ca 100644 --- a/fishd.c +++ b/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 );