Changeset 171ef85
- Timestamp:
- 2008-03-02T23:17:15Z (17 years ago)
- Branches:
- master
- Children:
- ed3ae7e
- Parents:
- b27557b
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ipc.c
rb27557b r171ef85 258 258 else 259 259 { 260 ipc_master_free_fd( source ); 261 } 262 263 return TRUE; 264 } 265 266 gboolean ipc_child_read( gpointer data, gint source, b_input_condition cond ) 267 { 268 char *buf, **cmd; 269 270 if( ( buf = ipc_readline( source ) ) ) 271 { 272 cmd = irc_parse_line( buf ); 273 if( cmd ) 274 ipc_command_exec( data, cmd, ipc_child_commands ); 275 } 276 else 277 { 278 ipc_child_disable(); 279 } 280 281 return TRUE; 282 } 283 284 void ipc_to_master( char **cmd ) 285 { 286 if( global.conf->runmode == RUNMODE_FORKDAEMON ) 287 { 288 char *s = irc_build_line( cmd ); 289 ipc_to_master_str( "%s", s ); 290 g_free( s ); 291 } 292 else if( global.conf->runmode == RUNMODE_DAEMON ) 293 { 294 ipc_command_exec( NULL, cmd, ipc_master_commands ); 295 } 296 } 297 298 void ipc_to_master_str( char *format, ... ) 299 { 300 char *msg_buf; 301 va_list params; 302 303 va_start( params, format ); 304 msg_buf = g_strdup_vprintf( format, params ); 305 va_end( params ); 306 307 if( strlen( msg_buf ) > 512 ) 308 { 309 /* Don't send it, it's too long... */ 310 } 311 else if( global.conf->runmode == RUNMODE_FORKDAEMON ) 312 { 313 if( global.listen_socket >= 0 ) 314 if( write( global.listen_socket, msg_buf, strlen( msg_buf ) ) <= 0 ) 315 ipc_child_disable(); 316 } 317 else if( global.conf->runmode == RUNMODE_DAEMON ) 318 { 319 char **cmd, *s; 320 321 if( ( s = strchr( msg_buf, '\r' ) ) ) 322 *s = 0; 323 324 cmd = irc_parse_line( msg_buf ); 325 ipc_command_exec( NULL, cmd, ipc_master_commands ); 326 g_free( cmd ); 327 } 328 329 g_free( msg_buf ); 330 } 331 332 void ipc_to_children( char **cmd ) 333 { 334 if( global.conf->runmode == RUNMODE_FORKDAEMON ) 335 { 336 char *msg_buf = irc_build_line( cmd ); 337 ipc_to_children_str( "%s", msg_buf ); 338 g_free( msg_buf ); 339 } 340 else if( global.conf->runmode == RUNMODE_DAEMON ) 341 { 260 342 GSList *l; 261 struct bitlbee_child *c; 262 263 for( l = child_list; l; l = l->next ) 343 344 for( l = irc_connection_list; l; l = l->next ) 345 ipc_command_exec( l->data, cmd, ipc_child_commands ); 346 } 347 } 348 349 void ipc_to_children_str( char *format, ... ) 350 { 351 char *msg_buf; 352 va_list params; 353 354 va_start( params, format ); 355 msg_buf = g_strdup_vprintf( format, params ); 356 va_end( params ); 357 358 if( strlen( msg_buf ) > 512 ) 359 { 360 /* Don't send it, it's too long... */ 361 } 362 else if( global.conf->runmode == RUNMODE_FORKDAEMON ) 363 { 364 int msg_len = strlen( msg_buf ); 365 GSList *l, *next; 366 367 for( l = child_list; l; l = next ) 264 368 { 265 c = l->data; 266 if( c->ipc_fd == source ) 369 struct bitlbee_child *c = l->data; 370 371 next = l->next; 372 if( write( c->ipc_fd, msg_buf, msg_len ) <= 0 ) 267 373 { 268 374 ipc_master_free_one( c ); 269 375 child_list = g_slist_remove( child_list, c ); 270 break;271 376 } 272 }273 }274 275 return TRUE;276 }277 278 gboolean ipc_child_read( gpointer data, gint source, b_input_condition cond )279 {280 char *buf, **cmd;281 282 if( ( buf = ipc_readline( source ) ) )283 {284 cmd = irc_parse_line( buf );285 if( cmd )286 ipc_command_exec( data, cmd, ipc_child_commands );287 }288 else289 {290 b_event_remove( global.listen_watch_source_id );291 close( global.listen_socket );292 293 global.listen_socket = -1;294 }295 296 return TRUE;297 }298 299 void ipc_to_master( char **cmd )300 {301 if( global.conf->runmode == RUNMODE_FORKDAEMON )302 {303 char *s = irc_build_line( cmd );304 ipc_to_master_str( "%s", s );305 g_free( s );306 }307 else if( global.conf->runmode == RUNMODE_DAEMON )308 {309 ipc_command_exec( NULL, cmd, ipc_master_commands );310 }311 }312 313 void ipc_to_master_str( char *format, ... )314 {315 char *msg_buf;316 va_list params;317 318 va_start( params, format );319 msg_buf = g_strdup_vprintf( format, params );320 va_end( params );321 322 if( strlen( msg_buf ) > 512 )323 {324 /* Don't send it, it's too long... */325 }326 else if( global.conf->runmode == RUNMODE_FORKDAEMON )327 {328 write( global.listen_socket, msg_buf, strlen( msg_buf ) );329 }330 else if( global.conf->runmode == RUNMODE_DAEMON )331 {332 char **cmd, *s;333 334 if( ( s = strchr( msg_buf, '\r' ) ) )335 *s = 0;336 337 cmd = irc_parse_line( msg_buf );338 ipc_command_exec( NULL, cmd, ipc_master_commands );339 g_free( cmd );340 }341 342 g_free( msg_buf );343 }344 345 void ipc_to_children( char **cmd )346 {347 if( global.conf->runmode == RUNMODE_FORKDAEMON )348 {349 char *msg_buf = irc_build_line( cmd );350 ipc_to_children_str( "%s", msg_buf );351 g_free( msg_buf );352 }353 else if( global.conf->runmode == RUNMODE_DAEMON )354 {355 GSList *l;356 357 for( l = irc_connection_list; l; l = l->next )358 ipc_command_exec( l->data, cmd, ipc_child_commands );359 }360 }361 362 void ipc_to_children_str( char *format, ... )363 {364 char *msg_buf;365 va_list params;366 367 va_start( params, format );368 msg_buf = g_strdup_vprintf( format, params );369 va_end( params );370 371 if( strlen( msg_buf ) > 512 )372 {373 /* Don't send it, it's too long... */374 }375 else if( global.conf->runmode == RUNMODE_FORKDAEMON )376 {377 int msg_len = strlen( msg_buf );378 GSList *l;379 380 for( l = child_list; l; l = l->next )381 {382 struct bitlbee_child *c = l->data;383 write( c->ipc_fd, msg_buf, msg_len );384 377 } 385 378 } … … 410 403 } 411 404 405 void ipc_master_free_fd( int fd ) 406 { 407 GSList *l; 408 struct bitlbee_child *c; 409 410 for( l = child_list; l; l = l->next ) 411 { 412 c = l->data; 413 if( c->ipc_fd == fd ) 414 { 415 ipc_master_free_one( c ); 416 child_list = g_slist_remove( child_list, c ); 417 break; 418 } 419 } 420 } 421 412 422 void ipc_master_free_all() 413 423 { … … 419 429 g_slist_free( child_list ); 420 430 child_list = NULL; 431 } 432 433 void ipc_child_disable() 434 { 435 b_event_remove( global.listen_watch_source_id ); 436 close( global.listen_socket ); 437 438 global.listen_socket = -1; 421 439 } 422 440 -
ipc.h
rb27557b r171ef85 44 44 45 45 void ipc_master_free_one( struct bitlbee_child *child ); 46 void ipc_master_free_fd( int fd ); 46 47 void ipc_master_free_all(); 48 49 void ipc_child_disable(); 47 50 48 51 void ipc_to_master( char **cmd );
Note: See TracChangeset
for help on using the changeset viewer.