- Timestamp:
- 2008-08-04T14:45:24Z (16 years ago)
- Branches:
- master
- Children:
- 87f525e
- Parents:
- 4ac647d (diff), 718e05f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ipc.c
r4ac647d r8661caa 33 33 34 34 GSList *child_list = NULL; 35 static char *statefile = NULL;36 35 37 36 static void ipc_master_cmd_client( irc_t *data, char **cmd ) … … 63 62 } 64 63 64 static void ipc_master_cmd_deaf( irc_t *data, char **cmd ) 65 { 66 if( global.conf->runmode == RUNMODE_DAEMON ) 67 { 68 b_event_remove( global.listen_watch_source_id ); 69 close( global.listen_socket ); 70 71 global.listen_socket = global.listen_watch_source_id = -1; 72 73 ipc_to_children_str( "OPERMSG :Closed listening socket, waiting " 74 "for all users to disconnect." ); 75 } 76 else 77 { 78 ipc_to_children_str( "OPERMSG :The DEAF command only works in " 79 "normal daemon mode. Try DIE instead." ); 80 } 81 } 82 65 83 void ipc_master_cmd_rehash( irc_t *data, char **cmd ) 66 84 { … … 98 116 { "hello", 0, ipc_master_cmd_client, 0 }, 99 117 { "die", 0, ipc_master_cmd_die, 0 }, 118 { "deaf", 0, ipc_master_cmd_deaf, 0 }, 100 119 { "wallops", 1, NULL, IPC_CMD_TO_CHILDREN }, 101 120 { "wall", 1, NULL, IPC_CMD_TO_CHILDREN }, … … 209 228 } 210 229 230 /* Return just one line. Returns NULL if something broke, an empty string 231 on temporary "errors" (EAGAIN and friends). */ 211 232 static char *ipc_readline( int fd ) 212 233 { 213 char *buf, *eol;234 char buf[513], *eol; 214 235 int size; 215 216 buf = g_new0( char, 513 );217 236 218 237 /* Because this is internal communication, it should be pretty safe … … 221 240 sockets and limites message length, messages should always be 222 241 complete. Saves us quite a lot of code and buffering. */ 223 size = recv( fd, buf, 512, MSG_PEEK );242 size = recv( fd, buf, sizeof( buf ) - 1, MSG_PEEK ); 224 243 if( size == 0 || ( size < 0 && !sockerr_again() ) ) 225 244 return NULL; … … 229 248 buf[size] = 0; 230 249 231 eol = strstr( buf, "\r\n" ); 232 if( eol == NULL ) 250 if( ( eol = strstr( buf, "\r\n" ) ) == NULL ) 233 251 return NULL; 234 252 else 235 253 size = eol - buf + 2; 236 237 g_free( buf );238 buf = g_new0( char, size + 1 );239 254 240 255 if( recv( fd, buf, size, 0 ) != size ) 241 256 return NULL; 242 257 else 243 buf[size-2] = 0; 244 245 return buf; 258 return g_strndup( buf, size - 2 ); 246 259 } 247 260 … … 254 267 cmd = irc_parse_line( buf ); 255 268 if( cmd ) 269 { 256 270 ipc_command_exec( data, cmd, ipc_master_commands ); 271 g_free( cmd ); 272 } 273 g_free( buf ); 257 274 } 258 275 else … … 272 289 cmd = irc_parse_line( buf ); 273 290 if( cmd ) 291 { 274 292 ipc_command_exec( data, cmd, ipc_child_commands ); 293 g_free( cmd ); 294 } 295 g_free( buf ); 275 296 } 276 297 else … … 439 460 } 440 461 462 #ifndef _WIN32 441 463 char *ipc_master_save_state() 442 464 { … … 479 501 } 480 502 481 void ipc_master_set_statefile( char *fn )482 {483 statefile = g_strdup( fn );484 }485 486 503 487 504 static gboolean new_ipc_client( gpointer data, gint serversock, b_input_condition cond ) … … 504 521 } 505 522 506 #ifndef _WIN32507 523 int ipc_master_listen_socket() 508 524 { … … 541 557 } 542 558 #else 559 int ipc_master_listen_socket() 560 { 543 561 /* FIXME: Open named pipe \\.\BITLBEE */ 562 return 0; 563 } 544 564 #endif 545 565 546 int ipc_master_load_state( )566 int ipc_master_load_state( char *statefile ) 547 567 { 548 568 struct bitlbee_child *child; … … 552 572 if( statefile == NULL ) 553 573 return 0; 574 554 575 fp = fopen( statefile, "r" ); 555 576 unlink( statefile ); /* Why do it later? :-) */
Note: See TracChangeset
for help on using the changeset viewer.