Exemple #1
0
int main(int argc, char* argv[]) { 
    if (argc < 2) { 
        printf("Usage: cleanupsem DATABASE-NAME\n");
        return 1;
    }
    char* databaseName = argv[1];    
    removeSharedMemory(databaseName, ".dm");    
    removeSemaphore(databaseName, ".in");    
    removeSemaphore(databaseName, ".ws");    
    removeSemaphore(databaseName, ".rs");    
    removeSemaphore(databaseName, ".us");    
    removeSemaphore(databaseName, ".bce");
    removeSemaphore(databaseName, ".dce");
    removeSemaphore(databaseName, ".cs");
    removeSemaphore(databaseName, ".mcs");
    printf("All semaphores are removed\n");
    return 0;
}
Exemple #2
0
int loadRuleFromCacheOrFile( int processType, char *irbSet, ruleStruct_t *inRuleStruct ) {
    char r1[NAME_LEN], r2[RULE_SET_DEF_LENGTH], r3[RULE_SET_DEF_LENGTH];
    snprintf( r2, sizeof( r2 ), "%s", irbSet );
    int res = 0;

#ifdef DEBUG
    /*Cache *cache;*/
#endif

    /* get max timestamp */
    char fn[MAX_NAME_LEN];
    time_type timestamp = time_type_initializer, mtim;
    while ( strlen( r2 ) > 0 ) {
        rSplitStr( r2, r1, NAME_LEN, r3, RULE_SET_DEF_LENGTH, ',' );
        getRuleBasePath( r1, fn );
        if ( ( res = getModifiedTime( fn, &mtim ) ) != 0 ) {
            return res;
        }
        if ( time_type_gt( mtim, timestamp ) ) {
            time_type_set( timestamp, mtim );
        }
        snprintf( r2, sizeof( r2 ), "%s", r3 );
    }
    snprintf( r2, sizeof( r2 ), "%s", irbSet );

#ifdef CACHE_ENABLE

    int update = 0;
    unsigned char *buf = NULL;
    /* try to find shared memory cache */
    if ( processType == RULE_ENGINE_TRY_CACHE && inRuleStruct == &coreRuleStrct ) {
        buf = prepareNonServerSharedMemory();
        if ( buf != NULL ) {
            Cache * cache = restoreCache( buf );
            detachSharedMemory();

            if ( cache == NULL ) {
                rodsLog( LOG_ERROR, "Failed to restore cache." );
            }
            else {
                int diffIrbSet = strcmp( cache->ruleBase, irbSet ) != 0;
                if ( diffIrbSet ) {
                    rodsLog( LOG_DEBUG, "Rule base set changed, old value is %s", cache->ruleBase );
                }

                if ( diffIrbSet || time_type_gt( timestamp, cache->timestamp ) ) {
                    update = 1;
                    free( cache->address );
                    rodsLog( LOG_DEBUG, "Rule base set or rule files modified, force refresh." );
                }
                else {

                    cache->cacheStatus = INITIALIZED;
                    ruleEngineConfig = *cache;
                    /* generate extRuleSet */
                    generateRegions();
                    generateRuleSets();
                    generateFunctionDescriptionTables();
                    if ( inRuleStruct == &coreRuleStrct && ruleEngineConfig.ruleEngineStatus == UNINITIALIZED ) {
                        getSystemFunctions( ruleEngineConfig.sysFuncDescIndex->current, ruleEngineConfig.sysRegion );
                    }
                    /* ruleEngineConfig.extRuleSetStatus = LOCAL;
                    ruleEngineConfig.extFuncDescIndexStatus = LOCAL; */
                    /* createRuleIndex(inRuleStruct); */
                    ruleEngineConfig.ruleEngineStatus = INITIALIZED;
                    //free( cache );
                    return res;
                }
            }
            //free( cache );
        }
        else {
            rodsLog( LOG_DEBUG, "Cannot open shared memory." );
        }
    }
#endif

    if ( ruleEngineConfig.ruleEngineStatus == INITIALIZED ) {
        /* Reloading rule set, clear previously generated rule set */
        unlinkFuncDescIndex();
        clearRuleIndex( inRuleStruct );
    }

    generateRegions();
    generateRuleSets();
    generateFunctionDescriptionTables();
    if ( inRuleStruct == &coreRuleStrct && ruleEngineConfig.ruleEngineStatus == UNINITIALIZED ) {
        getSystemFunctions( ruleEngineConfig.sysFuncDescIndex->current, ruleEngineConfig.sysRegion );
    }
    /*ruleEngineConfig.extRuleSetStatus = LOCAL;
    ruleEngineConfig.extFuncDescIndexStatus = LOCAL;*/
    while ( strlen( r2 ) > 0 ) {
        int i = rSplitStr( r2, r1, NAME_LEN, r3, RULE_SET_DEF_LENGTH, ',' );
        if ( i == 0 ) {
            i = readRuleStructAndRuleSetFromFile( r1, inRuleStruct );
        }
#ifdef DEBUG
        printf( "%d rules in core rule set\n", ruleEngineConfig.coreRuleSet->len );
#endif
        if ( i != 0 ) {
            res = i;
            ruleEngineConfig.ruleEngineStatus = INITIALIZED;
            return res;
        }
        snprintf( r2, sizeof( r2 ), "%s", r3 );
    }

    createRuleIndex( inRuleStruct );
    /* set max timestamp */
    time_type_set( ruleEngineConfig.timestamp, timestamp );
    snprintf( ruleEngineConfig.ruleBase, sizeof( ruleEngineConfig.ruleBase ), "%s", irbSet );

#ifdef CACHE_ENABLE
    if ( ( processType == RULE_ENGINE_INIT_CACHE || update ) && inRuleStruct == &coreRuleStrct ) {
        unsigned char *shared = prepareServerSharedMemory();

        if ( shared != NULL ) {
            int ret = updateCache( shared, SHMMAX, &ruleEngineConfig, processType );
            detachSharedMemory();
            if ( ret != 0 ) {
                removeSharedMemory();
            }
        }
        else {
            rodsLog( LOG_ERROR, "Cannot open shared memory." );
        }
    }
#endif

    ruleEngineConfig.ruleEngineStatus = INITIALIZED;

    return res;
}