Changeset f4a5940


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.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • commands.h

    r6fda350 rf4a5940  
    4444#define IRC_CMD_TO_MASTER       8
    4545
     46#define IPC_CMD_TO_CHILDREN     1
     47
    4648#endif
  • conf.c

    r6fda350 rf4a5940  
    6464        conf->ping_interval = 180;
    6565        conf->ping_timeout = 300;
     66        proxytype = 0;
    6667       
    6768        i = conf_loadini( conf, CONF_FILE );
     
    7677        }
    7778       
    78         while( ( opt = getopt( argc, argv, "i:p:nvIDFc:d:h" ) ) >= 0 )
     79        while( argc > 0 && ( opt = getopt( argc, argv, "i:p:nvIDFc:d:h" ) ) >= 0 )
     80        /*     ^^^^ Just to make sure we skip this step from the REHASH handler. */
    7981        {
    8082                if( opt == 'i' )
     
    108110                                CONF_FILE = g_strdup( optarg );
    109111                                g_free( conf );
    110                                 /* Re-evaluate arguments. */
     112                                /* Re-evaluate arguments. Don't use this option twice,
     113                                   you'll end up in an infinite loop! Hope this trick
     114                                   works with all libcs BTW.. */
    111115                                optind = 1;
    112116                                return( conf_load( argc, argv ) );
  • 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}
  • ipc.h

    r6fda350 rf4a5940  
    2929void ipc_master_read( gpointer data, gint source, GaimInputCondition cond );
    3030void ipc_child_read( gpointer data, gint source, GaimInputCondition cond );
     31
    3132void ipc_to_master( char **cmd );
     33void ipc_to_master_str( char *msg_buf );
    3234void ipc_to_children( char **cmd );
    3335void ipc_to_children_str( char *msg_buf );
  • irc_commands.c

    r6fda350 rf4a5940  
    233233}
    234234
    235 /* TODO: Attach this one to NOTICE too! */
    236235static int irc_cmd_privmsg( irc_t *irc, char **cmd )
    237236{
     
    530529}
    531530
    532 /* TODO: Alias to NS */
    533531static int irc_cmd_nickserv( irc_t *irc, char **cmd )
    534532{
     
    576574       
    577575        irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "END" );
     576       
     577        return( 1 );
     578}
     579
     580static int irc_cmd_rehash( irc_t *irc, char **cmd )
     581{
     582        ipc_to_master( cmd );
     583       
     584        irc_reply( irc, 382, "%s :Rehashing", CONF_FILE );
    578585       
    579586        return( 1 );
     
    610617        { "wallops",     0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
    611618        { "lilo",        0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
     619        { "rehash",      0, irc_cmd_rehash,      IRC_CMD_OPER_ONLY },
    612620        { NULL }
    613621};
Note: See TracChangeset for help on using the changeset viewer.