From a0d04d6253cf70877a11156059209e1f9a2efe31 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 7 May 2006 20:07:43 +0200 Subject: Got rid of all GLib GIOChannel-related calls outside proxy.c --- ipc.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 48bd574a..c16acd72 100644 --- a/ipc.c +++ b/ipc.c @@ -462,25 +462,21 @@ void ipc_master_set_statefile( char *fn ) } -static gboolean new_ipc_client (GIOChannel *gio, GIOCondition cond, gpointer data) +static void new_ipc_client( gpointer data, gint serversock, GaimInputCondition cond ) { struct bitlbee_child *child = g_new0( struct bitlbee_child, 1 ); - int serversock; - - serversock = g_io_channel_unix_get_fd(gio); - - child->ipc_fd = accept(serversock, NULL, 0); - - if (child->ipc_fd == -1) { + + child->ipc_fd = accept( serversock, NULL, 0 ); + + if( child->ipc_fd == -1 ) + { log_message( LOGLVL_WARNING, "Unable to accept connection on UNIX domain socket: %s", strerror(errno) ); - return TRUE; + return; } child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); - + child_list = g_slist_append( child_list, child ); - - return TRUE; } #ifndef _WIN32 @@ -488,7 +484,6 @@ int ipc_master_listen_socket() { struct sockaddr_un un_addr; int serversock; - GIOChannel *gio; /* Clean up old socket files that were hanging around.. */ if (unlink(IPCSOCKET) == -1 && errno != ENOENT) { @@ -516,14 +511,8 @@ int ipc_master_listen_socket() return 0; } - gio = g_io_channel_unix_new(serversock); + gaim_input_add( serversock, GAIM_INPUT_READ, new_ipc_client, NULL ); - if (gio == NULL) { - log_message( LOGLVL_WARNING, "Unable to create IO channel for unix socket" ); - return 0; - } - - g_io_add_watch(gio, G_IO_IN, new_ipc_client, NULL); return 1; } #else -- cgit v1.2.3 From ba9edaa568088900145bbd1004c864b7d408c38d Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 10 May 2006 19:34:46 +0200 Subject: Moved everything to the BitlBee event handling API. --- ipc.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index c16acd72..a8b110b6 100644 --- a/ipc.c +++ b/ipc.c @@ -59,7 +59,7 @@ static void ipc_master_cmd_die( irc_t *data, char **cmd ) if( global.conf->runmode == RUNMODE_FORKDAEMON ) ipc_to_children_str( "DIE\r\n" ); - bitlbee_shutdown( NULL ); + bitlbee_shutdown( NULL, -1, 0 ); } void ipc_master_cmd_rehash( irc_t *data, char **cmd ) @@ -90,7 +90,7 @@ void ipc_master_cmd_restart( irc_t *data, char **cmd ) } global.restart = -1; - bitlbee_shutdown( NULL ); + bitlbee_shutdown( NULL, -1, 0 ); } static const command_t ipc_master_commands[] = { @@ -245,7 +245,7 @@ static char *ipc_readline( int fd ) return buf; } -void ipc_master_read( gpointer data, gint source, GaimInputCondition cond ) +gboolean ipc_master_read( gpointer data, gint source, b_input_condition cond ) { char *buf, **cmd; @@ -271,9 +271,11 @@ void ipc_master_read( gpointer data, gint source, GaimInputCondition cond ) } } } + + return TRUE; } -void ipc_child_read( gpointer data, gint source, GaimInputCondition cond ) +gboolean ipc_child_read( gpointer data, gint source, b_input_condition cond ) { char *buf, **cmd; @@ -285,11 +287,13 @@ void ipc_child_read( gpointer data, gint source, GaimInputCondition cond ) } else { - gaim_input_remove( global.listen_watch_source_id ); + b_event_remove( global.listen_watch_source_id ); close( global.listen_socket ); global.listen_socket = -1; } + + return TRUE; } void ipc_to_master( char **cmd ) @@ -396,7 +400,7 @@ void ipc_to_children_str( char *format, ... ) void ipc_master_free_one( struct bitlbee_child *c ) { - gaim_input_remove( c->ipc_inpa ); + b_event_remove( c->ipc_inpa ); closesocket( c->ipc_fd ); g_free( c->host ); @@ -462,7 +466,7 @@ void ipc_master_set_statefile( char *fn ) } -static void new_ipc_client( gpointer data, gint serversock, GaimInputCondition cond ) +static gboolean new_ipc_client( gpointer data, gint serversock, b_input_condition cond ) { struct bitlbee_child *child = g_new0( struct bitlbee_child, 1 ); @@ -471,12 +475,14 @@ static void new_ipc_client( gpointer data, gint serversock, GaimInputCondition c if( child->ipc_fd == -1 ) { log_message( LOGLVL_WARNING, "Unable to accept connection on UNIX domain socket: %s", strerror(errno) ); - return; + return TRUE; } - child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); + child->ipc_inpa = b_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); child_list = g_slist_append( child_list, child ); + + return TRUE; } #ifndef _WIN32 @@ -511,7 +517,7 @@ int ipc_master_listen_socket() return 0; } - gaim_input_add( serversock, GAIM_INPUT_READ, new_ipc_client, NULL ); + b_input_add( serversock, GAIM_INPUT_READ, new_ipc_client, NULL ); return 1; } @@ -551,7 +557,7 @@ int ipc_master_load_state() fclose( fp ); return 0; } - child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); + child->ipc_inpa = b_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); child_list = g_slist_append( child_list, child ); } -- cgit v1.2.3 From 79e826a028f4b4c62c0c16e20af1fb13a9636324 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 15 Jun 2006 14:22:17 +0200 Subject: Converted irc->status to binary flags. (This also fixes auto-save-on-quit that broke because of USTATUS_SHUTDOWN. :-( ) --- ipc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 18d3284e..5a23d1f9 100644 --- a/ipc.c +++ b/ipc.c @@ -114,7 +114,7 @@ static void ipc_child_cmd_die( irc_t *irc, char **cmd ) static void ipc_child_cmd_wallops( irc_t *irc, char **cmd ) { - if( irc->status < USTATUS_LOGGED_IN ) + if( ! irc->status & USTATUS_LOGGED_IN ) return; if( strchr( irc->umode, 'w' ) ) @@ -123,7 +123,7 @@ static void ipc_child_cmd_wallops( irc_t *irc, char **cmd ) static void ipc_child_cmd_lilo( irc_t *irc, char **cmd ) { - if( irc->status < USTATUS_LOGGED_IN ) + if( ! irc->status & USTATUS_LOGGED_IN ) return; if( strchr( irc->umode, 's' ) ) @@ -132,7 +132,7 @@ static void ipc_child_cmd_lilo( irc_t *irc, char **cmd ) static void ipc_child_cmd_opermsg( irc_t *irc, char **cmd ) { - if( irc->status < USTATUS_LOGGED_IN ) + if( ! irc->status & USTATUS_LOGGED_IN ) return; if( strchr( irc->umode, 'o' ) ) @@ -153,7 +153,7 @@ static void ipc_child_cmd_rehash( irc_t *irc, char **cmd ) static void ipc_child_cmd_kill( irc_t *irc, char **cmd ) { - if( irc->status < USTATUS_LOGGED_IN ) + if( ! irc->status & USTATUS_LOGGED_IN ) return; if( nick_cmp( cmd[1], irc->nick ) != 0 ) @@ -165,7 +165,7 @@ static void ipc_child_cmd_kill( irc_t *irc, char **cmd ) static void ipc_child_cmd_hello( irc_t *irc, char **cmd ) { - if( irc->status < USTATUS_LOGGED_IN ) + if( ! irc->status & USTATUS_LOGGED_IN ) ipc_to_master_str( "HELLO\r\n" ); else ipc_to_master_str( "HELLO %s %s :%s\r\n", irc->host, irc->nick, irc->realname ); -- cgit v1.2.3 From 3af70b06b2f0fb0fb41a041f6d86e3711b9eea3f Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 15 Jun 2006 14:37:05 +0200 Subject: !x&y == (!x)&y, not !(x&y). --- ipc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 5a23d1f9..d7ef1020 100644 --- a/ipc.c +++ b/ipc.c @@ -114,7 +114,7 @@ static void ipc_child_cmd_die( irc_t *irc, char **cmd ) static void ipc_child_cmd_wallops( irc_t *irc, char **cmd ) { - if( ! irc->status & USTATUS_LOGGED_IN ) + if( !( irc->status & USTATUS_LOGGED_IN ) ) return; if( strchr( irc->umode, 'w' ) ) @@ -123,7 +123,7 @@ static void ipc_child_cmd_wallops( irc_t *irc, char **cmd ) static void ipc_child_cmd_lilo( irc_t *irc, char **cmd ) { - if( ! irc->status & USTATUS_LOGGED_IN ) + if( !( irc->status & USTATUS_LOGGED_IN ) ) return; if( strchr( irc->umode, 's' ) ) @@ -132,7 +132,7 @@ static void ipc_child_cmd_lilo( irc_t *irc, char **cmd ) static void ipc_child_cmd_opermsg( irc_t *irc, char **cmd ) { - if( ! irc->status & USTATUS_LOGGED_IN ) + if( !( irc->status & USTATUS_LOGGED_IN ) ) return; if( strchr( irc->umode, 'o' ) ) @@ -153,7 +153,7 @@ static void ipc_child_cmd_rehash( irc_t *irc, char **cmd ) static void ipc_child_cmd_kill( irc_t *irc, char **cmd ) { - if( ! irc->status & USTATUS_LOGGED_IN ) + if( !( irc->status & USTATUS_LOGGED_IN ) ) return; if( nick_cmp( cmd[1], irc->nick ) != 0 ) @@ -165,7 +165,7 @@ static void ipc_child_cmd_kill( irc_t *irc, char **cmd ) static void ipc_child_cmd_hello( irc_t *irc, char **cmd ) { - if( ! irc->status & USTATUS_LOGGED_IN ) + if( !( irc->status & USTATUS_LOGGED_IN ) ) ipc_to_master_str( "HELLO\r\n" ); else ipc_to_master_str( "HELLO %s %s :%s\r\n", irc->host, irc->nick, irc->realname ); -- cgit v1.2.3 From dfc8a468020935a444397129eb5b2579e1001cf2 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 24 Nov 2006 20:39:59 +0100 Subject: Bye bye lilo. I've never been a fan of yours, but let's not make fun of the dead... --- ipc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 28aa07cb..d0d2dff3 100644 --- a/ipc.c +++ b/ipc.c @@ -98,7 +98,7 @@ static const command_t ipc_master_commands[] = { { "hello", 0, ipc_master_cmd_client, 0 }, { "die", 0, ipc_master_cmd_die, 0 }, { "wallops", 1, NULL, IPC_CMD_TO_CHILDREN }, - { "lilo", 1, NULL, IPC_CMD_TO_CHILDREN }, + { "wall", 1, NULL, IPC_CMD_TO_CHILDREN }, { "opermsg", 1, NULL, IPC_CMD_TO_CHILDREN }, { "rehash", 0, ipc_master_cmd_rehash, 0 }, { "kill", 2, NULL, IPC_CMD_TO_CHILDREN }, @@ -121,7 +121,7 @@ static void ipc_child_cmd_wallops( irc_t *irc, char **cmd ) irc_write( irc, ":%s WALLOPS :%s", irc->myhost, cmd[1] ); } -static void ipc_child_cmd_lilo( irc_t *irc, char **cmd ) +static void ipc_child_cmd_wall( irc_t *irc, char **cmd ) { if( !( irc->status & USTATUS_LOGGED_IN ) ) return; @@ -174,7 +174,7 @@ static void ipc_child_cmd_hello( irc_t *irc, char **cmd ) static const command_t ipc_child_commands[] = { { "die", 0, ipc_child_cmd_die, 0 }, { "wallops", 1, ipc_child_cmd_wallops, 0 }, - { "lilo", 1, ipc_child_cmd_lilo, 0 }, + { "wall", 1, ipc_child_cmd_wall, 0 }, { "opermsg", 1, ipc_child_cmd_opermsg, 0 }, { "rehash", 0, ipc_child_cmd_rehash, 0 }, { "kill", 2, ipc_child_cmd_kill, 0 }, -- cgit v1.2.3 From 52744f8f65a278a59a8903d5c594e057d63c7006 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 17 Jan 2008 22:06:55 +0000 Subject: Fixing some Solaris compiler warnings (u_int->uint, adding some typecasts for pid_t variables). --- ipc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index d0d2dff3..384a9c33 100644 --- a/ipc.c +++ b/ipc.c @@ -51,7 +51,7 @@ static void ipc_master_cmd_client( irc_t *data, char **cmd ) if( g_strcasecmp( cmd[0], "CLIENT" ) == 0 ) ipc_to_children_str( "OPERMSG :Client connecting (PID=%d): %s@%s (%s)\r\n", - child ? child->pid : -1, cmd[2], cmd[1], cmd[3] ); + (int) ( child ? child->pid : -1 ), cmd[2], cmd[1], cmd[3] ); } static void ipc_master_cmd_die( irc_t *data, char **cmd ) @@ -445,7 +445,7 @@ char *ipc_master_save_state() fprintf( fp, "%d\n", i ); for( l = child_list; l; l = l->next ) - fprintf( fp, "%d %d\n", ((struct bitlbee_child*)l->data)->pid, + fprintf( fp, "%d %d\n", (int) ((struct bitlbee_child*)l->data)->pid, ((struct bitlbee_child*)l->data)->ipc_fd ); if( fclose( fp ) == 0 ) @@ -550,7 +550,7 @@ int ipc_master_load_state() { child = g_new0( struct bitlbee_child, 1 ); - if( fscanf( fp, "%d %d", &child->pid, &child->ipc_fd ) != 2 ) + if( fscanf( fp, "%d %d", (int *) &child->pid, &child->ipc_fd ) != 2 ) { log_message( LOGLVL_WARNING, "Unexpected end of file: Only processed %d clients.", i ); g_free( child ); -- cgit v1.2.3 From 171ef85781e08ccbd8a6a018e88b1ad3cb802f78 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 2 Mar 2008 23:17:15 +0000 Subject: Some saner error handling in ipc.c. One of the things I wanted to do for 1.2. --- ipc.c | 60 +++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'ipc.c') 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" ); -- cgit v1.2.3