Ignore:
Timestamp:
May 21, 2012, 2:07:46 AM (9 years ago)
Author:
jordan
Message:

(trunk libT) #4895 "SIGHUP race during session init" -- fixed with patch from gvdl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/daemon.c

    r13195 r13312  
    6060static bool paused = false;
    6161static bool closing = false;
     62static bool seenHUP = false;
    6263static tr_session * mySession = NULL;
    6364
     
    142143        case SIGHUP:
    143144        {
    144             tr_benc settings;
    145             const char * configDir = tr_sessionGetConfigDir( mySession );
    146             tr_inf( "Reloading settings from \"%s\"", configDir );
    147             tr_bencInitDict( &settings, 0 );
    148             tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_ENABLED, true );
    149             tr_sessionLoadSettings( &settings, configDir, MY_NAME );
    150             tr_sessionSet( mySession, &settings );
    151             tr_bencFree( &settings );
    152             tr_sessionReloadBlocklists( mySession );
     145            if( !mySession )
     146            {
     147                tr_inf( "Deferring reload until session is fully started." );
     148                seenHUP = true;
     149            }
     150            else
     151            {
     152                tr_benc settings;
     153                const char * configDir = tr_sessionGetConfigDir( mySession );
     154                tr_inf( "Reloading settings from \"%s\"", configDir );
     155                tr_bencInitDict( &settings, 0 );
     156                tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_ENABLED, true );
     157                tr_sessionLoadSettings( &settings, configDir, MY_NAME );
     158                tr_sessionSet( mySession, &settings );
     159                tr_bencFree( &settings );
     160                tr_sessionReloadBlocklists( mySession );
     161            }
    153162            break;
    154163        }
    155164
    156165        default:
     166            tr_err( "Unexpected signal(%d) in daemon, closing.", sig);
     167            /* no break */
     168
     169        case SIGINT:
     170        case SIGTERM:
    157171            closing = true;
    158172            break;
     
    342356    FILE * logfile = NULL;
    343357    bool pidfile_created = false;
     358    tr_session * session = NULL;
    344359
    345360    signal( SIGINT, gotsig );
     
    484499    tr_formatter_size_init( DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR );
    485500    tr_formatter_speed_init( SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR );
    486     mySession = tr_sessionInit( "daemon", configDir, true, &settings );
    487     tr_sessionSetRPCCallback( mySession, on_rpc_callback, NULL );
     501    session = tr_sessionInit( "daemon", configDir, true, &settings );
     502    tr_sessionSetRPCCallback( session, on_rpc_callback, NULL );
    488503    tr_ninf( NULL, "Using settings from \"%s\"", configDir );
    489     tr_sessionSaveSettings( mySession, configDir, &settings );
     504    tr_sessionSaveSettings( session, configDir, &settings );
    490505
    491506    pid_filename = NULL;
     
    507522    if( tr_bencDictFindBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &boolVal ) && boolVal )
    508523        tr_ninf( MY_NAME, "requiring authentication" );
     524
     525    mySession = session;
     526
     527    /* If we got a SIGHUP during startup, process that now. */
     528    if( seenHUP )
     529        gotsig( SIGHUP );
    509530
    510531    /* maybe add a watchdir */
Note: See TracChangeset for help on using the changeset viewer.