示例#1
0
/* Scan starter thread */
static void   *scan_starter( void *arg )
{
    int            rc;

    DisplayLog( LVL_VERB, FSSCAN_TAG, "Launching FS Scan starter thread" );

    if ( fsscan_flags & FLAG_ONCE )
    {
        rc = Robinhood_CheckScanDeadlines(  );
        if ( rc )
            DisplayLog( LVL_CRIT, FSSCAN_TAG, "Error %d checking FS Scan status", rc );
        pthread_exit( NULL );
        return NULL;
    }

    /* not a one-shot mode */
    while ( !terminate )
    {
        rc = Robinhood_CheckScanDeadlines(  );
        if ( rc )
            DisplayLog( LVL_CRIT, FSSCAN_TAG, "Error %d checking FS Scan status", rc );

        /* attente de la boucle suivante */
        rh_sleep( fs_scan_config.spooler_check_interval );
    }

    return NULL;
}
示例#2
0
/*
 * This function is blocking as long as the lock file is present.
 * Optionaly updates an action timestamp, at each test.
 */
void TestLockFile( time_t * p_last_action )
{

    while ( access( global_config.lock_file, F_OK ) == 0 )
    {
        if ( p_last_action )
            *p_last_action = time( NULL );

        DisplayLog( LVL_MAJOR, "LOCK", "Lock file %s detected, waiting %ds",
                    global_config.lock_file, TEST_LOCK_FILE_PERIOD );
        rh_sleep( TEST_LOCK_FILE_PERIOD );
    }

}
示例#3
0
static void   *signal_handler_thr( void *arg )
{
    struct sigaction act_sigterm;
    struct sigaction act_sigusr;

    /* create signal handlers */
    memset( &act_sigterm, 0, sizeof( act_sigterm ) );
    act_sigterm.sa_flags = 0;
    act_sigterm.sa_handler = terminate_handler;
    if ( sigaction( SIGTERM, &act_sigterm, NULL ) == -1
         || sigaction( SIGINT, &act_sigterm, NULL ) == -1 )
    {
        DisplayLog( LVL_CRIT, SIGHDL_TAG,
                    "Error while setting signal handlers for SIGTERM and SIGINT: %s",
                    strerror( errno ) );
        if (options.diff_arg.db_tag != NULL && ensure_db_access())
        {
            fprintf(stderr, "Cleaning diff table...\n");
            ListMgr_DestroyTag(&lmgr, options.diff_arg.db_tag);
        }
        exit( 1 );
    }
    else
        DisplayLog( LVL_EVENT, SIGHDL_TAG,
                    "Signals SIGTERM and SIGINT (daemon shutdown) are ready to be used" );

    memset( &act_sigusr, 0, sizeof( act_sigusr ) );
    act_sigusr.sa_flags = 0;
    act_sigusr.sa_handler = usr_handler;
    if ( sigaction( SIGUSR1, &act_sigusr, NULL ) == -1 )
    {
        DisplayLog( LVL_CRIT, SIGHDL_TAG, "Error while setting signal handlers for SIGUSR1: %s",
                    strerror( errno ) );
        if (options.diff_arg.db_tag != NULL && ensure_db_access())
        {
            fprintf(stderr, "Cleaning diff table...\n");
            ListMgr_DestroyTag(&lmgr, options.diff_arg.db_tag);

            /* make sure written data is flushed */
            if (options.diff_arg.lovea_file)
                fflush(options.diff_arg.lovea_file);
            if (options.diff_arg.fid_remap_file)
                fflush(options.diff_arg.fid_remap_file);
        }
        exit( 1 );
    }
    else
        DisplayLog( LVL_EVENT, SIGHDL_TAG, "Signal SIGUSR1 (stats dump) is ready to be used" );


    /* signal flag checking loop */

    while ( 1 )
    {
        /* check for signal every second */
        rh_sleep( 1 );

        if ( terminate_sig != 0 )
        {
            if ( terminate_sig == SIGTERM )
                DisplayLog( LVL_MAJOR, SIGHDL_TAG, "SIGTERM received: performing clean daemon shutdown" );
            else if ( terminate_sig == SIGINT )
                DisplayLog( LVL_MAJOR, SIGHDL_TAG, "SIGINT received: performing clean daemon shutdown" );
            FlushLogs(  );

            /* stop FS scan (blocking) */
            FSScan_Terminate(  );
            FlushLogs(  );

            /* drop pipeline waiting operations and terminate threads */
            EntryProcessor_Terminate( FALSE );
            FlushLogs(  );

#ifdef _HSM_LITE
            /* shutdown backend access */
            Backend_Stop();
#endif

            DisplayLog( LVL_MAJOR, SIGHDL_TAG, "Exiting." );
            FlushLogs(  );

            if (options.diff_arg.db_tag != NULL && ensure_db_access())
            {
                fprintf(stderr, "Cleaning diff table...\n");
                ListMgr_DestroyTag(&lmgr, options.diff_arg.db_tag);

                /* make sure written data is flushed */
                if (options.diff_arg.lovea_file)
                    fflush(options.diff_arg.lovea_file);
                if (options.diff_arg.fid_remap_file)
                    fflush(options.diff_arg.fid_remap_file);
            }

            /* indicate the process terminated due to a signal */
            exit( 128 + terminate_sig );
        }
        else if ( dump_sig )
        {
            DisplayLog( LVL_MAJOR, SIGHDL_TAG, "SIGUSR1 received: dumping stats" );

            if (!ensure_db_access())
                return NULL;
            dump_stats(&lmgr);
            dump_sig = FALSE;
        }
    }
}
示例#4
0
/* Wait for next stat deadline */
void WaitStatsInterval(void)
{
    rh_sleep(log_config.stats_interval > 0 ? log_config.stats_interval : 1);
}
示例#5
0
/* Wait for next stat deadline */
void WaitStatsInterval(  )
{
    rh_sleep( log_config.stats_interval );
}