Changeset f4a5940 for ipc.c


Ignore:
Timestamp:
2006-01-15T20:31:59Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
daa9e02
Parents:
6fda350
Message:

Added REHASH command, IPC emulation in daemon (non-forked) mode.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ipc.c

    r6fda350 rf4a5940  
    4242}
    4343
    44 static int ipc_master_cmd_wallops( irc_t *data, char **cmd )
    45 {
    46         ipc_to_children( cmd );
     44static int ipc_master_cmd_rehash( irc_t *data, char **cmd )
     45{
     46        runmode_t oldmode;
     47       
     48        oldmode = global.conf->runmode;
     49       
     50        g_free( global.conf );
     51        global.conf = conf_load( 0, NULL );
     52       
     53        if( global.conf->runmode != oldmode )
     54        {
     55                log_message( LOGLVL_WARNING, "Can't change RunMode setting at runtime, restoring original setting" );
     56                global.conf->runmode = oldmode;
     57        }
     58       
     59        if( global.conf->runmode == RUNMODE_FORKDAEMON )
     60                ipc_to_children( cmd );
    4761       
    4862        return 1;
     
    5165static const command_t ipc_master_commands[] = {
    5266        { "die",        0, ipc_master_cmd_die,        0 },
    53         { "wallops",    1, ipc_master_cmd_wallops,    0 },
    54         { "lilo",       1, ipc_master_cmd_wallops,    0 },
     67        { "wallops",    1, NULL,                      IPC_CMD_TO_CHILDREN },
     68        { "lilo",       1, NULL,                      IPC_CMD_TO_CHILDREN },
     69        { "rehash",     0, ipc_master_cmd_rehash,     0 },
    5570        { NULL }
    5671};
     
    8095        if( strchr( irc->umode, 's' ) )
    8196                irc_write( irc, ":%s NOTICE %s :%s", irc->myhost, irc->nick, cmd[1] );
     97       
     98        return 1;
     99}
     100
     101static int ipc_child_cmd_rehash( irc_t *data, char **cmd )
     102{
     103        runmode_t oldmode;
     104       
     105        oldmode = global.conf->runmode;
     106       
     107        g_free( global.conf );
     108        global.conf = conf_load( 0, NULL );
     109       
     110        global.conf->runmode = oldmode;
    82111       
    83112        return 1;
     
    88117        { "wallops",    1, ipc_child_cmd_wallops,     0 },
    89118        { "lilo",       1, ipc_child_cmd_lilo,        0 },
     119        { "rehash",     0, ipc_child_cmd_rehash,     0 },
    90120        { NULL }
    91121};
     
    102132                if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 )
    103133                {
    104                         commands[i].execute( data, cmd );
     134                        if( commands[i].flags & IPC_CMD_TO_CHILDREN )
     135                                ipc_to_children( cmd );
     136                        else
     137                                commands[i].execute( data, cmd );
     138                       
    105139                        return;
    106140                }
     
    198232        {
    199233                char *s = irc_build_line( cmd );
    200                 write( global.listen_socket, s, strlen( s ) );
     234                ipc_to_master_str( s );
     235                g_free( s );
     236        }
     237        else if( global.conf->runmode == RUNMODE_DAEMON )
     238        {
     239                ipc_command_exec( NULL, cmd, ipc_master_commands );
     240        }
     241}
     242
     243void ipc_to_master_str( char *msg_buf )
     244{
     245        if( global.conf->runmode == RUNMODE_FORKDAEMON )
     246        {
     247                write( global.listen_socket, msg_buf, strlen( msg_buf ) );
     248        }
     249        else if( global.conf->runmode == RUNMODE_DAEMON )
     250        {
     251                char *s, **cmd;
     252               
     253                /* irc_parse_line() wants a read-write string, so get it one: */
     254                s = g_strdup( msg_buf );
     255                cmd = irc_parse_line( s );
     256               
     257                ipc_command_exec( NULL, cmd, ipc_master_commands );
     258               
     259                g_free( cmd );
    201260                g_free( s );
    202261        }
     
    210269                ipc_to_children_str( msg_buf );
    211270                g_free( msg_buf );
     271        }
     272        else if( global.conf->runmode == RUNMODE_DAEMON )
     273        {
     274                GSList *l;
     275               
     276                for( l = irc_connection_list; l; l = l->next )
     277                        ipc_command_exec( l->data, cmd, ipc_child_commands );
    212278        }
    213279}
     
    226292                }
    227293        }
    228 }
     294        else if( global.conf->runmode == RUNMODE_DAEMON )
     295        {
     296                char *s, **cmd;
     297               
     298                /* irc_parse_line() wants a read-write string, so get it one: */
     299                s = g_strdup( msg_buf );
     300                cmd = irc_parse_line( s );
     301               
     302                ipc_to_children( cmd );
     303               
     304                g_free( cmd );
     305                g_free( s );
     306        }
     307}
Note: See TracChangeset for help on using the changeset viewer.