Skip to content

Commit c03933d

Browse files
committed
Merged (and adapted) changes from main tree.
2 parents 89bac36 + 1c4da00 commit c03933d

File tree

6 files changed

+89
-72
lines changed

6 files changed

+89
-72
lines changed

bitlbee.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit
169169
if( !irc_process( irc ) )
170170
{
171171
log_message( LOGLVL_INFO, "Destroying connection with fd %d.", irc->fd );
172-
irc_free( irc );
172+
irc_abort( irc );
173173
return FALSE;
174174
}
175175

176176
/* Very naughty, go read the RFCs! >:) */
177177
if( irc->readbuffer && ( strlen( irc->readbuffer ) > 1024 ) )
178178
{
179179
log_message( LOGLVL_ERROR, "Maximum line length exceeded." );
180-
irc_free( irc );
180+
irc_abort( irc );
181181
return FALSE;
182182
}
183183

@@ -196,25 +196,25 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi
196196
size = strlen( irc->sendbuffer );
197197
st = write( irc->fd, irc->sendbuffer, size );
198198

199-
if( st <= 0 )
199+
if( st == 0 || ( st < 0 && !sockerr_again() ) )
200200
{
201-
if( sockerr_again() )
202-
{
203-
return TRUE;
204-
}
205-
else
206-
{
207-
irc_free( irc );
208-
return FALSE;
209-
}
201+
irc_free( irc );
202+
return FALSE;
203+
}
204+
else if( st < 0 ) /* && sockerr_again() */
205+
{
206+
return TRUE;
210207
}
211208

212209
if( st == size )
213210
{
214211
g_free( irc->sendbuffer );
215212
irc->sendbuffer = NULL;
216-
217213
irc->w_watch_source_id = 0;
214+
215+
if( irc->status == USTATUS_SHUTDOWN )
216+
irc_free( irc );
217+
218218
return( FALSE );
219219
}
220220
else

ipc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ static int ipc_child_cmd_kill( irc_t *irc, char **cmd )
124124
return 1; /* It's not for us. */
125125

126126
irc_write( irc, ":%s!%s@%s KILL %s :%s", irc->mynick, irc->mynick, irc->myhost, irc->nick, cmd[2] );
127-
g_io_channel_close( irc->io_channel );
127+
irc_abort( irc );
128+
/* g_io_channel_close( irc->io_channel ); */
128129

129130
return 0;
130131
}

irc.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ irc_t *irc_new( int fd )
150150
return( irc );
151151
}
152152

153+
void irc_abort( irc_t *irc )
154+
{
155+
irc->status = USTATUS_SHUTDOWN;
156+
if( irc->sendbuffer )
157+
{
158+
g_source_remove( irc->r_watch_source_id );
159+
irc->r_watch_source_id = g_timeout_add_full( G_PRIORITY_HIGH, 1000, (GSourceFunc) irc_free, irc, NULL );
160+
}
161+
else
162+
{
163+
irc_free( irc );
164+
}
165+
}
166+
153167
static gboolean irc_free_userhash( gpointer key, gpointer value, gpointer data )
154168
{
155169
g_free( key );

irc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ typedef enum
4343
USTATUS_OFFLINE,
4444
USTATUS_AUTHORIZED,
4545
USTATUS_LOGGED_IN,
46-
USTATUS_IDENTIFIED
46+
USTATUS_IDENTIFIED,
47+
USTATUS_SHUTDOWN
4748
} irc_status_t;
4849

4950
typedef struct channel
@@ -103,6 +104,7 @@ typedef struct irc
103104
extern GSList *irc_connection_list;
104105

105106
irc_t *irc_new( int fd );
107+
void irc_abort( irc_t *irc );
106108
void irc_free( irc_t *irc );
107109

108110
int irc_exec( irc_t *irc, char **cmd );

irc_commands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static int irc_cmd_nick( irc_t *irc, char **cmd )
8181
static int irc_cmd_quit( irc_t *irc, char **cmd )
8282
{
8383
irc_write( irc, "ERROR :%s%s", cmd[1]?"Quit: ":"", cmd[1]?cmd[1]:"Client Quit" );
84-
g_io_channel_close( irc->io_channel );
84+
/* g_io_channel_close( irc->io_channel ); */
8585

8686
return( 0 );
8787
}

log.c

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ static void log_console(int level, char *logmessage);
3737
void log_init(void) {
3838
openlog("bitlbee", LOG_PID, LOG_DAEMON);
3939

40-
logoutput.informational=&log_null;
41-
logoutput.warning=&log_null;
42-
logoutput.error=&log_null;
40+
logoutput.informational = &log_null;
41+
logoutput.warning = &log_null;
42+
logoutput.error = &log_null;
4343
#ifdef DEBUG
44-
logoutput.debug=&log_null;
44+
logoutput.debug = &log_null;
4545
#endif
4646

4747
return;
@@ -50,46 +50,46 @@ void log_init(void) {
5050
void log_link(int level, int output) {
5151
/* I know it's ugly, but it works and I didn't feel like messing with pointer to function pointers */
5252

53-
if(level==LOGLVL_INFO) {
54-
if(output==LOGOUTPUT_NULL)
55-
logoutput.informational=&log_null;
56-
else if(output==LOGOUTPUT_IRC)
57-
logoutput.informational=&log_irc;
58-
else if(output==LOGOUTPUT_SYSLOG)
59-
logoutput.informational=&log_syslog;
60-
else if(output==LOGOUTPUT_CONSOLE)
61-
logoutput.informational=&log_console;
53+
if(level == LOGLVL_INFO) {
54+
if(output == LOGOUTPUT_NULL)
55+
logoutput.informational = &log_null;
56+
else if(output == LOGOUTPUT_IRC)
57+
logoutput.informational = &log_irc;
58+
else if(output == LOGOUTPUT_SYSLOG)
59+
logoutput.informational = &log_syslog;
60+
else if(output == LOGOUTPUT_CONSOLE)
61+
logoutput.informational = &log_console;
6262
}
63-
else if(level==LOGLVL_WARNING) {
64-
if(output==LOGOUTPUT_NULL)
65-
logoutput.warning=&log_null;
66-
else if(output==LOGOUTPUT_IRC)
67-
logoutput.warning=&log_irc;
68-
else if(output==LOGOUTPUT_SYSLOG)
69-
logoutput.warning=&log_syslog;
70-
else if(output==LOGOUTPUT_CONSOLE)
71-
logoutput.warning=&log_console;
63+
else if(level == LOGLVL_WARNING) {
64+
if(output == LOGOUTPUT_NULL)
65+
logoutput.warning = &log_null;
66+
else if(output == LOGOUTPUT_IRC)
67+
logoutput.warning = &log_irc;
68+
else if(output == LOGOUTPUT_SYSLOG)
69+
logoutput.warning = &log_syslog;
70+
else if(output == LOGOUTPUT_CONSOLE)
71+
logoutput.warning = &log_console;
7272
}
73-
else if(level==LOGLVL_ERROR) {
74-
if(output==LOGOUTPUT_NULL)
75-
logoutput.error=&log_null;
76-
else if(output==LOGOUTPUT_IRC)
77-
logoutput.error=&log_irc;
78-
else if(output==LOGOUTPUT_SYSLOG)
79-
logoutput.error=&log_syslog;
80-
else if(output==LOGOUTPUT_CONSOLE)
81-
logoutput.error=&log_console;
73+
else if(level == LOGLVL_ERROR) {
74+
if(output == LOGOUTPUT_NULL)
75+
logoutput.error = &log_null;
76+
else if(output == LOGOUTPUT_IRC)
77+
logoutput.error = &log_irc;
78+
else if(output == LOGOUTPUT_SYSLOG)
79+
logoutput.error = &log_syslog;
80+
else if(output == LOGOUTPUT_CONSOLE)
81+
logoutput.error = &log_console;
8282
}
8383
#ifdef DEBUG
84-
else if(level==LOGLVL_DEBUG) {
85-
if(output==LOGOUTPUT_NULL)
86-
logoutput.debug=&log_null;
87-
else if(output==LOGOUTPUT_IRC)
88-
logoutput.debug=&log_irc;
89-
else if(output==LOGOUTPUT_SYSLOG)
90-
logoutput.debug=&log_syslog;
91-
else if(output==LOGOUTPUT_CONSOLE)
92-
logoutput.debug=&log_console;
84+
else if(level == LOGLVL_DEBUG) {
85+
if(output == LOGOUTPUT_NULL)
86+
logoutput.debug = &log_null;
87+
else if(output == LOGOUTPUT_IRC)
88+
logoutput.debug = &log_irc;
89+
else if(output == LOGOUTPUT_SYSLOG)
90+
logoutput.debug = &log_syslog;
91+
else if(output == LOGOUTPUT_CONSOLE)
92+
logoutput.debug = &log_console;
9393
}
9494
#endif
9595
return;
@@ -105,14 +105,14 @@ void log_message(int level, char *message, ... ) {
105105
msgstring = g_strdup_vprintf(message, ap);
106106
va_end(ap);
107107

108-
if(level==LOGLVL_INFO)
108+
if(level == LOGLVL_INFO)
109109
(*(logoutput.informational))(level, msgstring);
110-
if(level==LOGLVL_WARNING)
110+
if(level == LOGLVL_WARNING)
111111
(*(logoutput.warning))(level, msgstring);
112-
if(level==LOGLVL_ERROR)
112+
if(level == LOGLVL_ERROR)
113113
(*(logoutput.error))(level, msgstring);
114114
#ifdef DEBUG
115-
if(level==LOGLVL_DEBUG)
115+
if(level == LOGLVL_DEBUG)
116116
(*(logoutput.debug))(level, msgstring);
117117
#endif
118118

@@ -132,43 +132,43 @@ static void log_null(int level, char *message) {
132132
}
133133

134134
static void log_irc(int level, char *message) {
135-
if(level==LOGLVL_ERROR)
135+
if(level == LOGLVL_ERROR)
136136
irc_write_all(1, "ERROR :Error: %s", message);
137-
if(level==LOGLVL_WARNING)
137+
if(level == LOGLVL_WARNING)
138138
irc_write_all(0, "ERROR :Warning: %s", message);
139-
if(level==LOGLVL_INFO)
139+
if(level == LOGLVL_INFO)
140140
irc_write_all(0, "ERROR :Informational: %s", message);
141141
#ifdef DEBUG
142-
if(level==LOGLVL_DEBUG)
142+
if(level == LOGLVL_DEBUG)
143143
irc_write_all(0, "ERROR :Debug: %s", message);
144144
#endif
145145

146146
return;
147147
}
148148

149149
static void log_syslog(int level, char *message) {
150-
if(level==LOGLVL_ERROR)
150+
if(level == LOGLVL_ERROR)
151151
syslog(LOG_ERR, "%s", message);
152-
if(level==LOGLVL_WARNING)
152+
if(level == LOGLVL_WARNING)
153153
syslog(LOG_WARNING, "%s", message);
154-
if(level==LOGLVL_INFO)
154+
if(level == LOGLVL_INFO)
155155
syslog(LOG_INFO, "%s", message);
156156
#ifdef DEBUG
157-
if(level==LOGLVL_DEBUG)
157+
if(level == LOGLVL_DEBUG)
158158
syslog(LOG_DEBUG, "%s", message);
159159
#endif
160160
return;
161161
}
162162

163163
static void log_console(int level, char *message) {
164-
if(level==LOGLVL_ERROR)
164+
if(level == LOGLVL_ERROR)
165165
fprintf(stderr, "Error: %s\n", message);
166-
if(level==LOGLVL_WARNING)
166+
if(level == LOGLVL_WARNING)
167167
fprintf(stderr, "Warning: %s\n", message);
168-
if(level==LOGLVL_INFO)
168+
if(level == LOGLVL_INFO)
169169
fprintf(stdout, "Informational: %s\n", message);
170170
#ifdef DEBUG
171-
if(level==LOGLVL_DEBUG)
171+
if(level == LOGLVL_DEBUG)
172172
fprintf(stdout, "Debug: %s\n", message);
173173
#endif
174174
return;

0 commit comments

Comments
 (0)