diff options
| -rw-r--r-- | ipc.c | 60 | ||||
| -rw-r--r-- | ipc.h | 3 | 
2 files changed, 42 insertions, 21 deletions
| @@ -257,19 +257,7 @@ gboolean ipc_master_read( gpointer data, gint source, b_input_condition cond )  	}  	else  	{ -		GSList *l; -		struct bitlbee_child *c; -		 -		for( l = child_list; l; l = l->next ) -		{ -			c = l->data; -			if( c->ipc_fd == source ) -			{ -				ipc_master_free_one( c ); -				child_list = g_slist_remove( child_list, c ); -				break; -			} -		} +		ipc_master_free_fd( source );  	}  	return TRUE; @@ -287,10 +275,7 @@ gboolean ipc_child_read( gpointer data, gint source, b_input_condition cond )  	}  	else  	{ -		b_event_remove( global.listen_watch_source_id ); -		close( global.listen_socket ); -		 -		global.listen_socket = -1; +		ipc_child_disable();  	}  	return TRUE; @@ -325,7 +310,9 @@ void ipc_to_master_str( char *format, ... )  	}  	else if( global.conf->runmode == RUNMODE_FORKDAEMON )  	{ -		write( global.listen_socket, msg_buf, strlen( msg_buf ) ); +		if( global.listen_socket >= 0 ) +			if( write( global.listen_socket, msg_buf, strlen( msg_buf ) ) <= 0 ) +				ipc_child_disable();  	}  	else if( global.conf->runmode == RUNMODE_DAEMON )  	{ @@ -375,12 +362,18 @@ void ipc_to_children_str( char *format, ... )  	else if( global.conf->runmode == RUNMODE_FORKDAEMON )  	{  		int msg_len = strlen( msg_buf ); -		GSList *l; +		GSList *l, *next; -		for( l = child_list; l; l = l->next ) +		for( l = child_list; l; l = next )  		{  			struct bitlbee_child *c = l->data; -			write( c->ipc_fd, msg_buf, msg_len ); +			 +			next = l->next; +			if( write( c->ipc_fd, msg_buf, msg_len ) <= 0 ) +			{ +				ipc_master_free_one( c ); +				child_list = g_slist_remove( child_list, c ); +			}  		}  	}  	else if( global.conf->runmode == RUNMODE_DAEMON ) @@ -409,6 +402,23 @@ void ipc_master_free_one( struct bitlbee_child *c )  	g_free( c );  } +void ipc_master_free_fd( int fd ) +{ +	GSList *l; +	struct bitlbee_child *c; +	 +	for( l = child_list; l; l = l->next ) +	{ +		c = l->data; +		if( c->ipc_fd == fd ) +		{ +			ipc_master_free_one( c ); +			child_list = g_slist_remove( child_list, c ); +			break; +		} +	} +} +  void ipc_master_free_all()  {  	GSList *l; @@ -420,6 +430,14 @@ void ipc_master_free_all()  	child_list = NULL;  } +void ipc_child_disable() +{ +	b_event_remove( global.listen_watch_source_id ); +	close( global.listen_socket ); +	 +	global.listen_socket = -1; +} +  char *ipc_master_save_state()  {  	char *fn = g_strdup( "/tmp/bee-restart.XXXXXX" ); @@ -43,8 +43,11 @@ gboolean ipc_master_read( gpointer data, gint source, b_input_condition cond );  gboolean ipc_child_read( gpointer data, gint source, b_input_condition cond );  void ipc_master_free_one( struct bitlbee_child *child ); +void ipc_master_free_fd( int fd );  void ipc_master_free_all(); +void ipc_child_disable(); +  void ipc_to_master( char **cmd );  void ipc_to_master_str( char *format, ... ) G_GNUC_PRINTF( 1, 2 );  void ipc_to_children( char **cmd ); | 
