aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2006-01-20 13:21:24 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2006-01-20 13:21:24 +0100
commitfc50d482ae5a7836fbf7c72df168b51d1cf714a5 (patch)
tree985aa41b83b307649b6d7f135a0dafbf1ba7aa6a
parent2fa825ba7c79a0ab4ed9a534865974e918b49100 (diff)
irc_abort() does logging (including a reason) now.
-rw-r--r--bitlbee.c11
-rw-r--r--irc.c38
-rw-r--r--irc.h2
3 files changed, 40 insertions, 11 deletions
diff --git a/bitlbee.c b/bitlbee.c
index d8bf12d7..891bd195 100644
--- a/bitlbee.c
+++ b/bitlbee.c
@@ -162,14 +162,14 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit
if( condition & G_IO_ERR || condition & G_IO_HUP )
{
- irc_free( irc );
+ irc_abort( irc, 1, "Read error" );
return FALSE;
}
st = read( irc->fd, line, sizeof( line ) - 1 );
if( st == 0 )
{
- irc_free( irc );
+ irc_abort( irc, 1, "Connection reset by peer" );
return FALSE;
}
else if( st < 0 )
@@ -180,7 +180,7 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit
}
else
{
- irc_free( irc );
+ irc_abort( irc, 1, "Read error: %s", strerror( errno ) );
return FALSE;
}
}
@@ -206,8 +206,7 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit
/* Very naughty, go read the RFCs! >:) */
if( irc->readbuffer && ( strlen( irc->readbuffer ) > 1024 ) )
{
- log_message( LOGLVL_ERROR, "Maximum line length exceeded." );
- irc_abort( irc );
+ irc_abort( irc, 0, "Maximum line length exceeded" );
return FALSE;
}
@@ -228,7 +227,7 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi
if( st == 0 || ( st < 0 && !sockerr_again() ) )
{
- irc_free( irc );
+ irc_abort( irc, 1, "Write error: %s", strerror( errno ) );
return FALSE;
}
else if( st < 0 ) /* && sockerr_again() */
diff --git a/irc.c b/irc.c
index 1055c3c8..f3e926f7 100644
--- a/irc.c
+++ b/irc.c
@@ -150,11 +150,42 @@ irc_t *irc_new( int fd )
return( irc );
}
-void irc_abort( irc_t *irc )
+void irc_abort( irc_t *irc, int immed, char *format, ... )
{
+ va_list params;
+
+ if( format != NULL )
+ {
+ char *reason;
+
+ va_start( params, format );
+ reason = g_strdup_printf( format, params );
+ va_end( params );
+
+ if( !immed )
+ irc_write( irc, "ERROR :Closing link: %s", reason );
+
+ ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n",
+ irc->nick, irc->host, reason" );
+
+ g_free( reason );
+ }
+ else
+ {
+ if( !immed )
+ irc_write( irc, "ERROR :Closing link" );
+
+ ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n",
+ irc->nick, irc->host, "No reason given" );
+ }
+
irc->status = USTATUS_SHUTDOWN;
- if( irc->sendbuffer )
+ if( irc->sendbuffer && !immed )
{
+ /* We won't read from this socket anymore. Instead, we'll connect a timer
+ to it that should shut down the connection in a second, just in case
+ bitlbee_.._write doesn't do it first. */
+
g_source_remove( irc->r_watch_source_id );
irc->r_watch_source_id = g_timeout_add_full( G_PRIORITY_HIGH, 1000, (GSourceFunc) irc_free, irc, NULL );
}
@@ -1622,8 +1653,7 @@ static gboolean irc_userping( gpointer _irc )
if( rv > 0 )
{
- irc_write( irc, "ERROR :Closing Link: Ping Timeout: %d seconds", rv );
- irc_free( irc );
+ irc_abort( irc, "ERROR :Closing Link: Ping Timeout: %d seconds", rv );
return FALSE;
}
diff --git a/irc.h b/irc.h
index 46391cb7..77628b26 100644
--- a/irc.h
+++ b/irc.h
@@ -104,7 +104,7 @@ typedef struct irc
extern GSList *irc_connection_list;
irc_t *irc_new( int fd );
-void irc_abort( irc_t *irc );
+void irc_abort( irc_t *irc, int immed, char *format, ... );
void irc_free( irc_t *irc );
int irc_exec( irc_t *irc, char **cmd );