Changeset e92c4f4 for ipc.c


Ignore:
Timestamp:
2010-07-11T00:29:19Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
1e52e1f
Parents:
f1c2b21
Message:

Takeover stuff now works in daemon mode as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ipc.c

    rf1c2b21 re92c4f4  
    171171        struct bitlbee_child *child = (void*) data;
    172172        char *fwd = NULL;
     173       
     174        /* Normal daemon mode doesn't keep these and has simplified code for
     175           takeovers. */
     176        if( child == NULL )
     177                return;
    173178       
    174179        if( child->to_child == NULL ||
     
    359364static void ipc_child_cmd_takeover_yes( void *data )
    360365{
    361         irc_t *irc = data;
     366        irc_t *irc = data, *old = NULL;
     367        char *to_auth[] = { "TAKEOVER", "AUTH", irc->user->nick, irc->password, NULL };
    362368       
    363369        /* Master->New connection */
     
    365371                           irc->user->nick, irc->password );
    366372       
     373        if( global.conf->runmode == RUNMODE_DAEMON )
     374        {
     375                GSList *l;
     376               
     377                for( l = irc_connection_list; l; l = l->next )
     378                {
     379                        old = l->data;
     380                       
     381                        if( irc != old &&
     382                            irc->user->nick && old->user->nick &&
     383                            irc->password && old->password &&
     384                            strcmp( irc->user->nick, old->user->nick ) == 0 &&
     385                            strcmp( irc->password, old->password ) == 0 )
     386                                break;
     387                }
     388                if( l == NULL )
     389                {
     390                        to_auth[1] = "FAIL";
     391                        ipc_child_cmd_takeover( irc, to_auth );
     392                        return;
     393                }
     394        }
     395       
    367396        /* Drop credentials, we'll shut down soon and shouldn't overwrite
    368397           any settings. */
    369398        irc_usermsg( irc, "Trying to take over existing session" );
     399       
     400        irc_desync( irc );
     401       
     402        if( old )
     403        {
     404                ipc_child_recv_fd = dup( irc->fd );
     405                ipc_child_cmd_takeover( old, to_auth );
     406        }
    370407       
    371408        /* TODO: irc_setpass() should do all of this. */
     
    374411        irc_umode_set( irc, "-R", 1 );
    375412       
    376         irc_desync( irc );
     413        if( old )
     414        {
     415                irc->status |= USTATUS_SHUTDOWN;
     416                irc_abort( irc, FALSE, NULL );
     417        }
    377418}
    378419
     
    403444       
    404445                ipc_to_master_str( "IDENTIFY %s :%s\r\n", irc->user->nick, irc->password );
     446               
     447                return TRUE;
     448        }
     449        else if( global.conf->runmode == RUNMODE_DAEMON )
     450        {
     451                GSList *l;
     452                irc_t *old;
     453                char *to_init[] = { "TAKEOVER", "INIT", NULL };
     454               
     455                for( l = irc_connection_list; l; l = l->next )
     456                {
     457                        old = l->data;
     458                       
     459                        if( irc != old &&
     460                            irc->user->nick && old->user->nick &&
     461                            irc->password && old->password &&
     462                            strcmp( irc->user->nick, old->user->nick ) == 0 &&
     463                            strcmp( irc->password, old->password ) == 0 )
     464                                break;
     465                }
     466                if( l == NULL )
     467                        return FALSE;
     468               
     469                ipc_child_cmd_takeover( irc, to_init );
    405470               
    406471                return TRUE;
     
    509574                               
    510575                                *recv_fd = *(int*) CMSG_DATA( cmsg );
     576                                /*
    511577                                fprintf( stderr, "pid %d received fd %d\n", (int) getpid(), *recv_fd );
     578                                */
    512579                        }
    513580       
     581        /*
    514582        fprintf( stderr, "pid %d received: %s", (int) getpid(), buf );
     583        */
    515584        return g_strndup( buf, size - 2 );
    516585}
Note: See TracChangeset for help on using the changeset viewer.