Changeset 74c119d for ipc.c


Ignore:
Timestamp:
2006-01-15T15:42:20Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
6fda350
Parents:
13caf0a
Message:

Better DIE implementation, added SO_REUSEADDR to listening socket.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ipc.c

    r13caf0a r74c119d  
    3131GSList *child_list = NULL;
    3232
     33
    3334static int ipc_master_cmd_die( irc_t *data, char **cmd )
    3435{
     36        if( global.conf->runmode == RUNMODE_FORKDAEMON )
     37                ipc_to_children_str( "DIE\r\n" );
     38       
    3539        bitlbee_shutdown( NULL );
     40       
     41        return 1;
    3642}
    3743
    3844static int ipc_master_cmd_wallops( irc_t *data, char **cmd )
    3945{
    40         GSList *l;
    41         char msg_buf[513];
    42         int msg_len;
    43        
    44         if( ( msg_len = g_snprintf( msg_buf, sizeof( msg_buf ) - 1, "%s :%s\r\n", cmd[0], cmd[1] ) ) > ( sizeof( msg_buf ) - 1 ) )
    45                 return 0;
    46        
    47         for( l = child_list; l; l = l->next )
    48         {
    49                 struct bitlbee_child *c = l->data;
    50                 write( c->ipc_fd, msg_buf, msg_len );
    51         }
     46        ipc_to_children( cmd );
    5247       
    5348        return 1;
     
    5651static const command_t ipc_master_commands[] = {
    5752        { "die",        0, ipc_master_cmd_die,        0 },
    58         { "wallops",    1, ipc_master_cmd_wallops,    1 },
    59         { "lilo",       1, ipc_master_cmd_wallops,    1 },
     53        { "wallops",    1, ipc_master_cmd_wallops,    0 },
     54        { "lilo",       1, ipc_master_cmd_wallops,    0 },
    6055        { NULL }
    6156};
    6257
     58
     59static int ipc_child_cmd_die( irc_t *data, char **cmd )
     60{
     61        bitlbee_shutdown( NULL );
     62       
     63        return 1;
     64}
     65
    6366static int ipc_child_cmd_wallops( irc_t *data, char **cmd )
    6467{
     
    7578        irc_t *irc = data;
    7679       
    77         irc_write( irc, ":%s NOTICE %s :%s", irc->myhost, irc->nick, cmd[1] );
     80        if( strchr( irc->umode, 's' ) )
     81                irc_write( irc, ":%s NOTICE %s :%s", irc->myhost, irc->nick, cmd[1] );
    7882       
    7983        return 1;
     
    8185
    8286static const command_t ipc_child_commands[] = {
    83         { "wallops",    1, ipc_child_cmd_wallops,     1 },
    84         { "lilo",       1, ipc_child_cmd_lilo,        1 },
     87        { "die",        0, ipc_child_cmd_die,         0 },
     88        { "wallops",    1, ipc_child_cmd_wallops,     0 },
     89        { "lilo",       1, ipc_child_cmd_lilo,        0 },
    8590        { NULL }
    8691};
     92
    8793
    8894static void ipc_command_exec( void *data, char **cmd, const command_t *commands )
     
    191197        if( global.conf->runmode == RUNMODE_FORKDAEMON )
    192198        {
    193                 int i, len;
    194                 char *s;
     199                char *s = irc_build_line( cmd );
     200                write( global.listen_socket, s, strlen( s ) );
     201                g_free( s );
     202        }
     203}
     204
     205void ipc_to_children( char **cmd )
     206{
     207        if( global.conf->runmode == RUNMODE_FORKDAEMON )
     208        {
     209                char *msg_buf = irc_build_line( cmd );
     210                ipc_to_children_str( msg_buf );
     211                g_free( msg_buf );
     212        }
     213}
     214
     215void ipc_to_children_str( char *msg_buf )
     216{
     217        if( global.conf->runmode == RUNMODE_FORKDAEMON )
     218        {
     219                int msg_len = strlen( msg_buf );
     220                GSList *l;
    195221               
    196                 len = 1;
    197                 for( i = 0; cmd[i]; i ++ )
    198                         len += strlen( cmd[i] ) + 1;
    199                
    200                 if( strchr( cmd[i-1], ' ' ) != NULL )
    201                         len ++;
    202                
    203                 s = g_new0( char, len + 1 );
    204                 for( i = 0; cmd[i]; i ++ )
     222                for( l = child_list; l; l = l->next )
    205223                {
    206                         if( cmd[i+1] == NULL && strchr( cmd[i], ' ' ) != NULL )
    207                                 strcat( s, ":" );
    208                        
    209                         strcat( s, cmd[i] );
    210                        
    211                         if( cmd[i+1] )
    212                                 strcat( s, " " );
     224                        struct bitlbee_child *c = l->data;
     225                        write( c->ipc_fd, msg_buf, msg_len );
    213226                }
    214                 strcat( s, "\r\n" );
    215                
    216                 write( global.listen_socket, s, len );
    217         }
    218 }
     227        }
     228}
Note: See TracChangeset for help on using the changeset viewer.