From e0ca412a709c80cc7fe26db0576c2bc38be4a45a Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 15 Jan 2006 12:33:54 +0100 Subject: s/WALLOP/WALLOPS/, added LILO command. --- ipc.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 81ef4ce8..a60a1c0c 100644 --- a/ipc.c +++ b/ipc.c @@ -32,16 +32,17 @@ GSList *child_list = NULL; static int ipc_master_cmd_die( irc_t *data, char **cmd ) { + /* This shouldn't really be the final implementation... */ exit( 0 ); } -static int ipc_master_cmd_wallop( irc_t *data, char **cmd ) +static int ipc_master_cmd_wallops( irc_t *data, char **cmd ) { GSList *l; char msg_buf[513]; int msg_len; - if( ( msg_len = g_snprintf( msg_buf, sizeof( msg_buf ) - 1, "WALLOP :%s\r\n", cmd[1] ) ) > ( sizeof( msg_buf ) - 1 ) ) + if( ( msg_len = g_snprintf( msg_buf, sizeof( msg_buf ) - 1, "%s :%s\r\n", cmd[0], cmd[1] ) ) > ( sizeof( msg_buf ) - 1 ) ) return 0; for( l = child_list; l; l = l->next ) @@ -55,22 +56,33 @@ static int ipc_master_cmd_wallop( irc_t *data, char **cmd ) static const command_t ipc_master_commands[] = { { "die", 0, ipc_master_cmd_die, 0 }, - { "wallop", 1, ipc_master_cmd_wallop, 1 }, + { "wallops", 1, ipc_master_cmd_wallops, 1 }, + { "lilo", 1, ipc_master_cmd_wallops, 1 }, { NULL } }; -static int ipc_child_cmd_wallop( irc_t *data, char **cmd ) +static int ipc_child_cmd_wallops( irc_t *data, char **cmd ) { irc_t *irc = data; if( strchr( irc->umode, 'w' ) ) - irc_write( irc, ":%s WALLOP :%s", irc->myhost, cmd[1] ); + irc_write( irc, ":%s WALLOPS :%s", irc->myhost, cmd[1] ); + + return 1; +} + +static int ipc_child_cmd_lilo( irc_t *data, char **cmd ) +{ + irc_t *irc = data; + + irc_write( irc, ":%s NOTICE %s :%s", irc->myhost, irc->nick, cmd[1] ); return 1; } static const command_t ipc_child_commands[] = { - { "wallop", 1, ipc_child_cmd_wallop, 1 }, + { "wallops", 1, ipc_child_cmd_wallops, 1 }, + { "lilo", 1, ipc_child_cmd_lilo, 1 }, { NULL } }; -- cgit v1.2.3 From 13caf0aa5d1e5575b74221e0cd9e4ff9f4cd79a8 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 15 Jan 2006 15:16:49 +0100 Subject: Better implementation of /DIE --- ipc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index a60a1c0c..03c44827 100644 --- a/ipc.c +++ b/ipc.c @@ -32,8 +32,7 @@ GSList *child_list = NULL; static int ipc_master_cmd_die( irc_t *data, char **cmd ) { - /* This shouldn't really be the final implementation... */ - exit( 0 ); + bitlbee_shutdown( NULL ); } static int ipc_master_cmd_wallops( irc_t *data, char **cmd ) -- cgit v1.2.3 From 74c119dd1b066329eba59d057935ba7ec7249555 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 15 Jan 2006 16:42:20 +0100 Subject: Better DIE implementation, added SO_REUSEADDR to listening socket. --- ipc.c | 86 +++++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 48 insertions(+), 38 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 03c44827..f7435776 100644 --- a/ipc.c +++ b/ipc.c @@ -30,36 +30,39 @@ GSList *child_list = NULL; + static int 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 ); + + return 1; } static int ipc_master_cmd_wallops( irc_t *data, char **cmd ) { - GSList *l; - char msg_buf[513]; - int msg_len; - - if( ( msg_len = g_snprintf( msg_buf, sizeof( msg_buf ) - 1, "%s :%s\r\n", cmd[0], cmd[1] ) ) > ( sizeof( msg_buf ) - 1 ) ) - return 0; - - for( l = child_list; l; l = l->next ) - { - struct bitlbee_child *c = l->data; - write( c->ipc_fd, msg_buf, msg_len ); - } + ipc_to_children( cmd ); return 1; } static const command_t ipc_master_commands[] = { { "die", 0, ipc_master_cmd_die, 0 }, - { "wallops", 1, ipc_master_cmd_wallops, 1 }, - { "lilo", 1, ipc_master_cmd_wallops, 1 }, + { "wallops", 1, ipc_master_cmd_wallops, 0 }, + { "lilo", 1, ipc_master_cmd_wallops, 0 }, { NULL } }; + +static int ipc_child_cmd_die( irc_t *data, char **cmd ) +{ + bitlbee_shutdown( NULL ); + + return 1; +} + static int ipc_child_cmd_wallops( irc_t *data, char **cmd ) { irc_t *irc = data; @@ -74,17 +77,20 @@ static int ipc_child_cmd_lilo( irc_t *data, char **cmd ) { irc_t *irc = data; - irc_write( irc, ":%s NOTICE %s :%s", irc->myhost, irc->nick, cmd[1] ); + if( strchr( irc->umode, 's' ) ) + irc_write( irc, ":%s NOTICE %s :%s", irc->myhost, irc->nick, cmd[1] ); return 1; } static const command_t ipc_child_commands[] = { - { "wallops", 1, ipc_child_cmd_wallops, 1 }, - { "lilo", 1, ipc_child_cmd_lilo, 1 }, + { "die", 0, ipc_child_cmd_die, 0 }, + { "wallops", 1, ipc_child_cmd_wallops, 0 }, + { "lilo", 1, ipc_child_cmd_lilo, 0 }, { NULL } }; + static void ipc_command_exec( void *data, char **cmd, const command_t *commands ) { int i; @@ -190,29 +196,33 @@ void ipc_to_master( char **cmd ) { if( global.conf->runmode == RUNMODE_FORKDAEMON ) { - int i, len; - char *s; - - len = 1; - for( i = 0; cmd[i]; i ++ ) - len += strlen( cmd[i] ) + 1; - - if( strchr( cmd[i-1], ' ' ) != NULL ) - len ++; + char *s = irc_build_line( cmd ); + write( global.listen_socket, s, strlen( s ) ); + g_free( s ); + } +} + +void ipc_to_children( char **cmd ) +{ + if( global.conf->runmode == RUNMODE_FORKDAEMON ) + { + char *msg_buf = irc_build_line( cmd ); + ipc_to_children_str( msg_buf ); + g_free( msg_buf ); + } +} + +void ipc_to_children_str( char *msg_buf ) +{ + if( global.conf->runmode == RUNMODE_FORKDAEMON ) + { + int msg_len = strlen( msg_buf ); + GSList *l; - s = g_new0( char, len + 1 ); - for( i = 0; cmd[i]; i ++ ) + for( l = child_list; l; l = l->next ) { - if( cmd[i+1] == NULL && strchr( cmd[i], ' ' ) != NULL ) - strcat( s, ":" ); - - strcat( s, cmd[i] ); - - if( cmd[i+1] ) - strcat( s, " " ); + struct bitlbee_child *c = l->data; + write( c->ipc_fd, msg_buf, msg_len ); } - strcat( s, "\r\n" ); - - write( global.listen_socket, s, len ); } } -- cgit v1.2.3 From f4a59408250b76173418fad090d4623e5300c90f Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 15 Jan 2006 21:31:59 +0100 Subject: Added REHASH command, IPC emulation in daemon (non-forked) mode. --- ipc.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 6 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index f7435776..5d6790f0 100644 --- a/ipc.c +++ b/ipc.c @@ -41,17 +41,32 @@ static int ipc_master_cmd_die( irc_t *data, char **cmd ) return 1; } -static int ipc_master_cmd_wallops( irc_t *data, char **cmd ) +static int ipc_master_cmd_rehash( irc_t *data, char **cmd ) { - ipc_to_children( cmd ); + runmode_t oldmode; + + oldmode = global.conf->runmode; + + g_free( global.conf ); + global.conf = conf_load( 0, NULL ); + + if( global.conf->runmode != oldmode ) + { + log_message( LOGLVL_WARNING, "Can't change RunMode setting at runtime, restoring original setting" ); + global.conf->runmode = oldmode; + } + + if( global.conf->runmode == RUNMODE_FORKDAEMON ) + ipc_to_children( cmd ); return 1; } static const command_t ipc_master_commands[] = { { "die", 0, ipc_master_cmd_die, 0 }, - { "wallops", 1, ipc_master_cmd_wallops, 0 }, - { "lilo", 1, ipc_master_cmd_wallops, 0 }, + { "wallops", 1, NULL, IPC_CMD_TO_CHILDREN }, + { "lilo", 1, NULL, IPC_CMD_TO_CHILDREN }, + { "rehash", 0, ipc_master_cmd_rehash, 0 }, { NULL } }; @@ -83,10 +98,25 @@ static int ipc_child_cmd_lilo( irc_t *data, char **cmd ) return 1; } +static int ipc_child_cmd_rehash( irc_t *data, char **cmd ) +{ + runmode_t oldmode; + + oldmode = global.conf->runmode; + + g_free( global.conf ); + global.conf = conf_load( 0, NULL ); + + global.conf->runmode = oldmode; + + return 1; +} + 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 }, + { "rehash", 0, ipc_child_cmd_rehash, 0 }, { NULL } }; @@ -101,7 +131,11 @@ static void ipc_command_exec( void *data, char **cmd, const command_t *commands for( i = 0; commands[i].command; i ++ ) if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) { - commands[i].execute( data, cmd ); + if( commands[i].flags & IPC_CMD_TO_CHILDREN ) + ipc_to_children( cmd ); + else + commands[i].execute( data, cmd ); + return; } } @@ -197,7 +231,32 @@ void ipc_to_master( char **cmd ) if( global.conf->runmode == RUNMODE_FORKDAEMON ) { char *s = irc_build_line( cmd ); - write( global.listen_socket, s, strlen( s ) ); + ipc_to_master_str( s ); + g_free( s ); + } + else if( global.conf->runmode == RUNMODE_DAEMON ) + { + ipc_command_exec( NULL, cmd, ipc_master_commands ); + } +} + +void ipc_to_master_str( char *msg_buf ) +{ + if( global.conf->runmode == RUNMODE_FORKDAEMON ) + { + write( global.listen_socket, msg_buf, strlen( msg_buf ) ); + } + else if( global.conf->runmode == RUNMODE_DAEMON ) + { + char *s, **cmd; + + /* irc_parse_line() wants a read-write string, so get it one: */ + s = g_strdup( msg_buf ); + cmd = irc_parse_line( s ); + + ipc_command_exec( NULL, cmd, ipc_master_commands ); + + g_free( cmd ); g_free( s ); } } @@ -210,6 +269,13 @@ void ipc_to_children( char **cmd ) ipc_to_children_str( msg_buf ); g_free( msg_buf ); } + else if( global.conf->runmode == RUNMODE_DAEMON ) + { + GSList *l; + + for( l = irc_connection_list; l; l = l->next ) + ipc_command_exec( l->data, cmd, ipc_child_commands ); + } } void ipc_to_children_str( char *msg_buf ) @@ -225,4 +291,17 @@ void ipc_to_children_str( char *msg_buf ) write( c->ipc_fd, msg_buf, msg_len ); } } + else if( global.conf->runmode == RUNMODE_DAEMON ) + { + char *s, **cmd; + + /* irc_parse_line() wants a read-write string, so get it one: */ + s = g_strdup( msg_buf ); + cmd = irc_parse_line( s ); + + ipc_to_children( cmd ); + + g_free( cmd ); + g_free( s ); + } } -- cgit v1.2.3 From daa9e027e8c8d1bc91e104dba985d5d44fef8c77 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 17 Jan 2006 19:05:22 +0100 Subject: LILO/WALLOPS commands now check if the receiving user logged in yet. --- ipc.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 5d6790f0..5e7b7821 100644 --- a/ipc.c +++ b/ipc.c @@ -82,6 +82,9 @@ static int ipc_child_cmd_wallops( irc_t *data, char **cmd ) { irc_t *irc = data; + if( irc->status < USTATUS_LOGGED_IN ) + return 1; + if( strchr( irc->umode, 'w' ) ) irc_write( irc, ":%s WALLOPS :%s", irc->myhost, cmd[1] ); @@ -92,6 +95,9 @@ static int ipc_child_cmd_lilo( irc_t *data, char **cmd ) { irc_t *irc = data; + if( irc->status < USTATUS_LOGGED_IN ) + return 1; + if( strchr( irc->umode, 's' ) ) irc_write( irc, ":%s NOTICE %s :%s", irc->myhost, irc->nick, cmd[1] ); -- cgit v1.2.3 From 48721c328e574e0ff76c41734b78aab217edbf65 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 17 Jan 2006 22:15:42 +0100 Subject: A KILL command. Unfortunately the user doesn't see the KILL message yet. :-( --- ipc.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 5e7b7821..cd30eb52 100644 --- a/ipc.c +++ b/ipc.c @@ -31,7 +31,7 @@ GSList *child_list = NULL; -static int ipc_master_cmd_die( irc_t *data, char **cmd ) +static int ipc_master_cmd_die( irc_t *irc, char **cmd ) { if( global.conf->runmode == RUNMODE_FORKDAEMON ) ipc_to_children_str( "DIE\r\n" ); @@ -41,7 +41,7 @@ static int ipc_master_cmd_die( irc_t *data, char **cmd ) return 1; } -static int ipc_master_cmd_rehash( irc_t *data, char **cmd ) +static int ipc_master_cmd_rehash( irc_t *irc, char **cmd ) { runmode_t oldmode; @@ -67,21 +67,20 @@ static const command_t ipc_master_commands[] = { { "wallops", 1, NULL, IPC_CMD_TO_CHILDREN }, { "lilo", 1, NULL, IPC_CMD_TO_CHILDREN }, { "rehash", 0, ipc_master_cmd_rehash, 0 }, + { "kill", 2, NULL, IPC_CMD_TO_CHILDREN }, { NULL } }; -static int ipc_child_cmd_die( irc_t *data, char **cmd ) +static int ipc_child_cmd_die( irc_t *irc, char **cmd ) { bitlbee_shutdown( NULL ); return 1; } -static int ipc_child_cmd_wallops( irc_t *data, char **cmd ) +static int ipc_child_cmd_wallops( irc_t *irc, char **cmd ) { - irc_t *irc = data; - if( irc->status < USTATUS_LOGGED_IN ) return 1; @@ -91,10 +90,8 @@ static int ipc_child_cmd_wallops( irc_t *data, char **cmd ) return 1; } -static int ipc_child_cmd_lilo( irc_t *data, char **cmd ) +static int ipc_child_cmd_lilo( irc_t *irc, char **cmd ) { - irc_t *irc = data; - if( irc->status < USTATUS_LOGGED_IN ) return 1; @@ -104,7 +101,7 @@ static int ipc_child_cmd_lilo( irc_t *data, char **cmd ) return 1; } -static int ipc_child_cmd_rehash( irc_t *data, char **cmd ) +static int ipc_child_cmd_rehash( irc_t *irc, char **cmd ) { runmode_t oldmode; @@ -118,11 +115,26 @@ static int ipc_child_cmd_rehash( irc_t *data, char **cmd ) return 1; } +static int ipc_child_cmd_kill( irc_t *irc, char **cmd ) +{ + if( irc->status < USTATUS_LOGGED_IN ) + return 1; + + if( nick_cmp( cmd[1], irc->nick ) != 0 ) + return 1; /* It's not for us. */ + + irc_write( irc, ":%s!%s@%s KILL %s :%s", irc->mynick, irc->mynick, irc->myhost, irc->nick, cmd[2] ); + g_io_channel_close( irc->io_channel ); + + return 0; +} + 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 }, - { "rehash", 0, ipc_child_cmd_rehash, 0 }, + { "rehash", 0, ipc_child_cmd_rehash, 0 }, + { "kill", 2, ipc_child_cmd_kill, 0 }, { NULL } }; -- cgit v1.2.3 From 1ea13be2cf335a471f85ea54d610fb91b7d14564 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 18 Jan 2006 19:14:35 +0100 Subject: Fixed a bad mistake in ipc_readline() error handling. --- ipc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index cd30eb52..dfde24bd 100644 --- a/ipc.c +++ b/ipc.c @@ -173,6 +173,8 @@ static char *ipc_readline( int fd ) size = recv( fd, buf, 512, MSG_PEEK ); if( size == 0 || ( size < 0 && !sockerr_again() ) ) return NULL; + else if( size < 0 ) /* && sockerr_again() */ + return( g_strdup( "" ) ); else buf[size] = 0; -- cgit v1.2.3 From bd9b00f4fed3560eab98f15cf9923aed13467d5d Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 19 Jan 2006 18:07:47 +0100 Subject: Fixes for single-process daemon mode, changed value of USTATUS_SHUTDOWN. If this still causes problems, shutting down should be an extra flag instead of a status code. --- ipc.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 5fda047c..4777113a 100644 --- a/ipc.c +++ b/ipc.c @@ -35,12 +35,15 @@ static int ipc_master_cmd_client( irc_t *data, char **cmd ) { struct bitlbee_child *child = (void*) data; - child->host = g_strdup( cmd[1] ); - child->nick = g_strdup( cmd[2] ); - child->realname = g_strdup( cmd[3] ); + if( child ) + { + child->host = g_strdup( cmd[1] ); + child->nick = g_strdup( cmd[2] ); + child->realname = g_strdup( cmd[3] ); + } ipc_to_children_str( "OPERMSG :Client connecting (PID=%d): %s@%s (%s)\r\n", - child->pid, child->nick, child->host, child->realname ); + child ? child->pid : -1, cmd[2], cmd[1], cmd[3] ); return 1; } @@ -307,7 +310,10 @@ void ipc_to_master_str( char *format, ... ) } else if( global.conf->runmode == RUNMODE_DAEMON ) { - char **cmd; + char **cmd, *s; + + if( ( s = strchr( msg_buf, '\r' ) ) ) + *s = 0; cmd = irc_parse_line( msg_buf ); ipc_command_exec( NULL, cmd, ipc_master_commands ); @@ -360,7 +366,10 @@ void ipc_to_children_str( char *format, ... ) } else if( global.conf->runmode == RUNMODE_DAEMON ) { - char **cmd; + char **cmd, *s; + + if( ( s = strchr( msg_buf, '\r' ) ) ) + *s = 0; cmd = irc_parse_line( msg_buf ); ipc_to_children( cmd ); -- cgit v1.2.3 From 5424c76c7813f82e2f98546f6a46b73d80181877 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 19 Jan 2006 18:52:19 +0100 Subject: Rehash command now also works in inetd mode. Other "IPC" commands only make sense in daemon mode. --- ipc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 4777113a..e0bf1319 100644 --- a/ipc.c +++ b/ipc.c @@ -58,7 +58,7 @@ static int ipc_master_cmd_die( irc_t *data, char **cmd ) return 1; } -static int ipc_master_cmd_rehash( irc_t *data, char **cmd ) +int ipc_master_cmd_rehash( irc_t *data, char **cmd ) { runmode_t oldmode; -- cgit v1.2.3 From f73b9697f9be18e04ec7458634520f9dd2e2432f Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 20 Jan 2006 16:15:49 +0100 Subject: Renamed commands.c, got rid of return values in all command functions. --- ipc.c | 54 ++++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index e0bf1319..8d44e4eb 100644 --- a/ipc.c +++ b/ipc.c @@ -31,7 +31,7 @@ GSList *child_list = NULL; -static int ipc_master_cmd_client( irc_t *data, char **cmd ) +static void ipc_master_cmd_client( irc_t *data, char **cmd ) { struct bitlbee_child *child = (void*) data; @@ -44,21 +44,17 @@ static int ipc_master_cmd_client( irc_t *data, char **cmd ) ipc_to_children_str( "OPERMSG :Client connecting (PID=%d): %s@%s (%s)\r\n", child ? child->pid : -1, cmd[2], cmd[1], cmd[3] ); - - return 1; } -static int ipc_master_cmd_die( irc_t *data, char **cmd ) +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 ); - - return 1; } -int ipc_master_cmd_rehash( irc_t *data, char **cmd ) +void ipc_master_cmd_rehash( irc_t *data, char **cmd ) { runmode_t oldmode; @@ -75,8 +71,6 @@ int ipc_master_cmd_rehash( irc_t *data, char **cmd ) if( global.conf->runmode == RUNMODE_FORKDAEMON ) ipc_to_children( cmd ); - - return 1; } static const command_t ipc_master_commands[] = { @@ -91,50 +85,39 @@ static const command_t ipc_master_commands[] = { }; -static int ipc_child_cmd_die( irc_t *irc, char **cmd ) +static void ipc_child_cmd_die( irc_t *irc, char **cmd ) { - if( irc->status >= USTATUS_LOGGED_IN ) - irc_write( irc, "ERROR :Operator requested server shutdown, bye bye!" ); - - irc_abort( irc ); - - return 1; + irc_abort( irc, 1, "Shutdown requested by operator" ); } -static int ipc_child_cmd_wallops( irc_t *irc, char **cmd ) +static void ipc_child_cmd_wallops( irc_t *irc, char **cmd ) { if( irc->status < USTATUS_LOGGED_IN ) - return 1; + return; if( strchr( irc->umode, 'w' ) ) irc_write( irc, ":%s WALLOPS :%s", irc->myhost, cmd[1] ); - - return 1; } -static int ipc_child_cmd_lilo( irc_t *irc, char **cmd ) +static void ipc_child_cmd_lilo( irc_t *irc, char **cmd ) { if( irc->status < USTATUS_LOGGED_IN ) - return 1; + return; if( strchr( irc->umode, 's' ) ) irc_write( irc, ":%s NOTICE %s :%s", irc->myhost, irc->nick, cmd[1] ); - - return 1; } -static int ipc_child_cmd_opermsg( irc_t *irc, char **cmd ) +static void ipc_child_cmd_opermsg( irc_t *irc, char **cmd ) { if( irc->status < USTATUS_LOGGED_IN ) - return 1; + return; if( strchr( irc->umode, 'o' ) ) irc_write( irc, ":%s NOTICE %s :*** OperMsg *** %s", irc->myhost, irc->nick, cmd[1] ); - - return 1; } -static int ipc_child_cmd_rehash( irc_t *irc, char **cmd ) +static void ipc_child_cmd_rehash( irc_t *irc, char **cmd ) { runmode_t oldmode; @@ -144,23 +127,18 @@ static int ipc_child_cmd_rehash( irc_t *irc, char **cmd ) global.conf = conf_load( 0, NULL ); global.conf->runmode = oldmode; - - return 1; } -static int ipc_child_cmd_kill( irc_t *irc, char **cmd ) +static void ipc_child_cmd_kill( irc_t *irc, char **cmd ) { if( irc->status < USTATUS_LOGGED_IN ) - return 1; + return; if( nick_cmp( cmd[1], irc->nick ) != 0 ) - return 1; /* It's not for us. */ + return; /* It's not for us. */ irc_write( irc, ":%s!%s@%s KILL %s :%s", irc->mynick, irc->mynick, irc->myhost, irc->nick, cmd[2] ); - irc_abort( irc ); - /* g_io_channel_close( irc->io_channel ); */ - - return 0; + irc_abort( irc, 0, "Killed by operator: %s", cmd[2] ); } static const command_t ipc_child_commands[] = { -- cgit v1.2.3 From f1d38f20f760376f43b90a105486cf3ff2fbf2c4 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 21 Jan 2006 23:23:58 +0100 Subject: Fixed counting of arguments in i[rp]c_exec(), made them a bit too simple. --- ipc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 8d44e4eb..3528988f 100644 --- a/ipc.c +++ b/ipc.c @@ -154,7 +154,7 @@ static const command_t ipc_child_commands[] = { static void ipc_command_exec( void *data, char **cmd, const command_t *commands ) { - int i; + int i, j; if( !cmd[0] ) return; @@ -162,12 +162,18 @@ static void ipc_command_exec( void *data, char **cmd, const command_t *commands for( i = 0; commands[i].command; i ++ ) if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) { + /* There is no typo in this line: */ + for( j = 1; cmd[j]; j ++ ); j --; + + if( j < commands[i].required_parameters ) + break; + if( commands[i].flags & IPC_CMD_TO_CHILDREN ) ipc_to_children( cmd ); else commands[i].execute( data, cmd ); - return; + break; } } -- cgit v1.2.3 From 87de505f3203054a2a0becbea5a064d24ab2cde3 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 22 Jan 2006 01:15:03 +0100 Subject: Quit message was invisible on /DIE. --- ipc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 3528988f..aba59bda 100644 --- a/ipc.c +++ b/ipc.c @@ -87,7 +87,7 @@ static const command_t ipc_master_commands[] = { static void ipc_child_cmd_die( irc_t *irc, char **cmd ) { - irc_abort( irc, 1, "Shutdown requested by operator" ); + irc_abort( irc, 0, "Shutdown requested by operator" ); } static void ipc_child_cmd_wallops( irc_t *irc, char **cmd ) -- cgit v1.2.3 From 6dff9d4ac2cbd279e25db60ae26086c830764682 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 1 Mar 2006 22:08:03 +0100 Subject: Also listen for admin connections on a unix domain socket at /var/run/bitlbee --- ipc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 778f74c8..b05958ae 100644 --- a/ipc.c +++ b/ipc.c @@ -27,6 +27,9 @@ #include "bitlbee.h" #include "ipc.h" #include "commands.h" +#ifndef _WIN32 +#include +#endif GSList *child_list = NULL; static char *statefile = NULL; @@ -456,6 +459,51 @@ void ipc_master_set_statefile( char *fn ) statefile = g_strdup( fn ); } + +static gboolean new_ipc_client (GIOChannel *gio, GIOCondition cond, gpointer data) +{ + 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); + + 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 +int ipc_master_listen_socket() +{ + struct sockaddr_un un_addr; + int serversock; + GIOChannel *gio; + + /* Clean up old socket files that were hanging around.. */ + unlink(IPCSOCKET); + + un_addr.sun_family = AF_UNIX; + strcpy(un_addr.sun_path, IPCSOCKET); + + serversock = socket(AF_UNIX, SOCK_STREAM, PF_UNIX); + + bind(serversock, &un_addr, sizeof(un_addr)); + + listen(serversock, 5); + + gio = g_io_channel_unix_new(serversock); + + g_io_add_watch(gio, G_IO_IN, new_ipc_client, NULL); + return 1; +} +#else + /* FIXME: Open named pipe \\.\BITLBEE */ +#endif + int ipc_master_load_state() { struct bitlbee_child *child; -- cgit v1.2.3 From 5e713f695f93f7dc88f225bf6a8cd16e228eff11 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 1 Mar 2006 23:17:57 +0100 Subject: Added a little comment for this scary cast. (-: --- ipc.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index 778f74c8..60caba3e 100644 --- a/ipc.c +++ b/ipc.c @@ -33,6 +33,10 @@ static char *statefile = NULL; static void ipc_master_cmd_client( irc_t *data, char **cmd ) { + /* Normally data points at an irc_t block, but for the IPC master + this is different. We think this scary cast is better than + creating a new command_t structure, just to make the compiler + happy. */ struct bitlbee_child *child = (void*) data; if( child && cmd[1] ) -- cgit v1.2.3 From 8a56e52a518855150525eab9e0fcdbe776223ffc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 1 Mar 2006 23:30:10 +0100 Subject: Improve error handling --- ipc.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'ipc.c') diff --git a/ipc.c b/ipc.c index b05958ae..366b1119 100644 --- a/ipc.c +++ b/ipc.c @@ -468,6 +468,11 @@ static gboolean new_ipc_client (GIOChannel *gio, GIOCondition cond, gpointer dat serversock = g_io_channel_unix_get_fd(gio); 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; + } child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); @@ -484,18 +489,37 @@ int ipc_master_listen_socket() GIOChannel *gio; /* Clean up old socket files that were hanging around.. */ - unlink(IPCSOCKET); + if (unlink(IPCSOCKET) == -1 && errno != ENOENT) { + log_message( LOGLVL_ERROR, "Could not remove old IPC socket at %s: %s", IPCSOCKET, strerror(errno) ); + return 0; + } un_addr.sun_family = AF_UNIX; strcpy(un_addr.sun_path, IPCSOCKET); serversock = socket(AF_UNIX, SOCK_STREAM, PF_UNIX); - bind(serversock, &un_addr, sizeof(un_addr)); + if (serversock == -1) { + log_message( LOGLVL_WARNING, "Unable to create UNIX socket: %s", strerror(errno) ); + return 0; + } + + if (bind(serversock, &un_addr, sizeof(un_addr)) == -1) { + log_message( LOGLVL_WARNING, "Unable to bind UNIX socket to %s: %s", IPCSOCKET, strerror(errno) ); + return 0; + } - listen(serversock, 5); + if (listen(serversock, 5) == -1) { + log_message( LOGLVL_WARNING, "Unable to listen on UNIX socket: %s", strerror(errno) ); + return 0; + } gio = g_io_channel_unix_new(serversock); + + 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; -- cgit v1.2.3