aboutsummaryrefslogtreecommitdiffstats
path: root/ipc.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-04-02 15:28:23 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-04-02 15:28:23 +0200
commitdd345753c1742905c9f81aa71d8b09109fbc5456 (patch)
tree8689e25f6465c17c3dd5913af6ae289bf13768d4 /ipc.c
parent0db75ad966458610427dacdd31ecbaddbca18935 (diff)
parentfa75134008bd9206ca02380927c27581feb65c3e (diff)
merge trunk.
Diffstat (limited to 'ipc.c')
-rw-r--r--ipc.c60
1 files changed, 39 insertions, 21 deletions
diff --git a/ipc.c b/ipc.c
index 384a9c33..54f026ac 100644
--- a/ipc.c
+++ b/ipc.c
@@ -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" );