Changeset 8661caa for ipc.c


Ignore:
Timestamp:
2008-08-04T14:45:24Z (16 years ago)
Author:
ulim <a.sporto+bee@…>
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.
Message:

merged in upstream r410.

Only conflict was the correction of jabber normalization which I had already done.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ipc.c

    r4ac647d r8661caa  
    3333
    3434GSList *child_list = NULL;
    35 static char *statefile = NULL;
    3635
    3736static void ipc_master_cmd_client( irc_t *data, char **cmd )
     
    6362}
    6463
     64static 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
    6583void ipc_master_cmd_rehash( irc_t *data, char **cmd )
    6684{
     
    98116        { "hello",      0, ipc_master_cmd_client,     0 },
    99117        { "die",        0, ipc_master_cmd_die,        0 },
     118        { "deaf",       0, ipc_master_cmd_deaf,       0 },
    100119        { "wallops",    1, NULL,                      IPC_CMD_TO_CHILDREN },
    101120        { "wall",       1, NULL,                      IPC_CMD_TO_CHILDREN },
     
    209228}
    210229
     230/* Return just one line. Returns NULL if something broke, an empty string
     231   on temporary "errors" (EAGAIN and friends). */
    211232static char *ipc_readline( int fd )
    212233{
    213         char *buf, *eol;
     234        char buf[513], *eol;
    214235        int size;
    215        
    216         buf = g_new0( char, 513 );
    217236       
    218237        /* Because this is internal communication, it should be pretty safe
     
    221240           sockets and limites message length, messages should always be
    222241           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 );
    224243        if( size == 0 || ( size < 0 && !sockerr_again() ) )
    225244                return NULL;
     
    229248                buf[size] = 0;
    230249       
    231         eol = strstr( buf, "\r\n" );
    232         if( eol == NULL )
     250        if( ( eol = strstr( buf, "\r\n" ) ) == NULL )
    233251                return NULL;
    234252        else
    235253                size = eol - buf + 2;
    236        
    237         g_free( buf );
    238         buf = g_new0( char, size + 1 );
    239254       
    240255        if( recv( fd, buf, size, 0 ) != size )
    241256                return NULL;
    242257        else
    243                 buf[size-2] = 0;
    244        
    245         return buf;
     258                return g_strndup( buf, size - 2 );
    246259}
    247260
     
    254267                cmd = irc_parse_line( buf );
    255268                if( cmd )
     269                {
    256270                        ipc_command_exec( data, cmd, ipc_master_commands );
     271                        g_free( cmd );
     272                }
     273                g_free( buf );
    257274        }
    258275        else
     
    272289                cmd = irc_parse_line( buf );
    273290                if( cmd )
     291                {
    274292                        ipc_command_exec( data, cmd, ipc_child_commands );
     293                        g_free( cmd );
     294                }
     295                g_free( buf );
    275296        }
    276297        else
     
    439460}
    440461
     462#ifndef _WIN32
    441463char *ipc_master_save_state()
    442464{
     
    479501}
    480502
    481 void ipc_master_set_statefile( char *fn )
    482 {
    483         statefile = g_strdup( fn );
    484 }
    485 
    486503
    487504static gboolean new_ipc_client( gpointer data, gint serversock, b_input_condition cond )
     
    504521}
    505522
    506 #ifndef _WIN32
    507523int ipc_master_listen_socket()
    508524{
     
    541557}
    542558#else
     559int ipc_master_listen_socket()
     560{
    543561        /* FIXME: Open named pipe \\.\BITLBEE */
     562        return 0;
     563}
    544564#endif
    545565
    546 int ipc_master_load_state()
     566int ipc_master_load_state( char *statefile )
    547567{
    548568        struct bitlbee_child *child;
     
    552572        if( statefile == NULL )
    553573                return 0;
     574       
    554575        fp = fopen( statefile, "r" );
    555576        unlink( statefile );    /* Why do it later? :-) */
Note: See TracChangeset for help on using the changeset viewer.