Exemple #1
0
void *lookupFromEnv(Env *env, char *key) {
    void* val = lookupFromHashTable(env->current, key);
    if(val==NULL && env->previous!=NULL) {
        val = lookupFromEnv(env->previous, key);
    }
    return val;
}
int
syncLazyUploadBufferedFile (const char *path, struct fuse_file_info *fi) {
    int status;
    char iRODSPath[MAX_NAME_LEN];
    lazyUploadFileInfo_t *lazyUploadFileInfo = NULL;

    // convert input path to iRODSPath
    status = _getiRODSPath(path, iRODSPath);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "syncLazyUploadBufferedFile: failed to get iRODS path - %s", path);
        return status;
    }

    LOCK(LazyUploadLock);

    lazyUploadFileInfo = (lazyUploadFileInfo_t *)lookupFromHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath);
    if(lazyUploadFileInfo != NULL) {
        // has lazy-upload file handle opened
        status = _commitLocalBuffer(iRODSPath, fi, lazyUploadFileInfo);
        if(status < 0) {
            rodsLog (LOG_DEBUG, "syncLazyUploadBufferedFile: failed to commit local buffer - %s", iRODSPath);
            UNLOCK(LazyUploadLock);
            return status; 
        }
    }
    
    UNLOCK(LazyUploadLock);
    return status;
}
int
isFilePreloading (const char *path) {
    int status;
    preloadThreadInfo_t *threadInfo = NULL;
    char iRODSPath[MAX_NAME_LEN];

    // convert input path to iRODSPath
    status = _getiRODSPath(path, iRODSPath);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "isFilePreloading: failed to get iRODS path - %s", path);
        return status;
    }

    // check the given file is already preloaded or preloading
    LOCK(PreloadLock);

    // check the given file is preloading
    threadInfo = (preloadThreadInfo_t *)lookupFromHashTable(PreloadThreadTable, iRODSPath);
    if(threadInfo != NULL) {
        UNLOCK(PreloadLock);
        return 0;
    }

    UNLOCK(PreloadLock);
    return -1;
}
void removeRuleFromExtIndex(char *ruleName, int i) {
	if(isComponentInitialized(ruleEngineConfig.extFuncDescIndexStatus)) {
		FunctionDesc *fd = (FunctionDesc *)lookupFromHashTable(ruleEngineConfig.extFuncDescIndex->current, ruleName);
		RuleIndexList *rd = FD_RULE_INDEX_LIST(fd);
		removeNodeFromRuleIndexList2(rd, i);
		if(rd->head == NULL) {
			deleteFromHashTable(ruleEngineConfig.extFuncDescIndex->current, ruleName);
		}
	}

}
Exemple #5
0
void updateInEnv(Env *env, char *varName, Res *res) {
    Env *defined = env;

    while(defined  != NULL && lookupFromHashTable(defined->current, varName) == NULL) {
        defined  = defined ->previous;
    }
    if(defined != NULL) {
        updateInHashTable(defined->current, varName, res);
    } else {
        insertIntoHashTable(env->current, varName, res);
    }
}
void prependRuleIntoAppIndex(RuleDesc *rule, int i, Region *r) {
	RuleIndexList *rd;
	FunctionDesc *fd = (FunctionDesc *)lookupFromHashTable(ruleEngineConfig.appFuncDescIndex->current, RULE_NAME(rule->node));
	if(fd == NULL) {
		rd = newRuleIndexList(RULE_NAME(rule->node), i, r);
		fd = newRuleIndexListFD(rd, NULL, r);
		insertIntoHashTable(ruleEngineConfig.appFuncDescIndex->current, RULE_NAME(rule->node), fd);
	} else {
		rd = FD_RULE_INDEX_LIST(fd);
		prependRuleNodeToRuleIndexList(rd, i ,r);
	}
}
Exemple #7
0
ExprType *dereference(ExprType *type, Hashtable *type_table, Region *r) {
    if(getNodeType(type) == T_VAR) {
        char name[128];
        getTVarName(T_VAR_ID(type), name);
        /* printf("deref: %s\n", name); */
        ExprType *deref = (ExprType *)lookupFromHashTable(type_table, name);
        if(deref == NULL)
            return type;
        else
            return dereference(deref, type_table, r);
    }
    return type;
}
Exemple #8
0
ExprType *dupTypeAux(ExprType *ty, Region *r, Hashtable *varTable) {
    ExprType **paramTypes;
    int i;
    ExprType *newt;
    ExprType *exist;
    char *name;
    char buf[128];
    switch(getNodeType(ty)) {
        case T_CONS:
            paramTypes = (ExprType **) region_alloc(r,sizeof(ExprType *)*T_CONS_ARITY(ty));
            for(i=0;i<T_CONS_ARITY(ty);i++) {
                paramTypes[i] = dupTypeAux(T_CONS_TYPE_ARG(ty, i),r,varTable);
            }
            newt = newConsType(T_CONS_ARITY(ty), T_CONS_TYPE_NAME(ty), paramTypes, r);
            newt->option = ty->option;
            break;
        case T_TUPLE:
            paramTypes = (ExprType **) region_alloc(r,sizeof(ExprType *)*T_CONS_ARITY(ty));
            for(i=0;i<T_CONS_ARITY(ty);i++) {
                paramTypes[i] = dupTypeAux(T_CONS_TYPE_ARG(ty, i),r,varTable);
            }
            newt = newTupleType(T_CONS_ARITY(ty), paramTypes, r);
            newt->option = ty->option;
            break;
        case T_VAR:
            name = getTVarName(T_VAR_ID(ty), buf);
            exist = (ExprType *)lookupFromHashTable(varTable, name);
            if(exist != NULL)
                newt = exist;
            else {
                newt = newTVar2(T_VAR_NUM_DISJUNCTS(ty), T_VAR_DISJUNCTS(ty), r);
                insertIntoHashTable(varTable, name, newt);

            }
            newt->option = ty->option;
            break;
        case T_FLEX:
            paramTypes = (ExprType **) region_alloc(r,sizeof(ExprType *)*1);
            paramTypes[0] = dupTypeAux(ty->subtrees[0],r,varTable);
            newt = newExprType(T_FLEX, 1, paramTypes, r);
            newt->option = ty->option;
            break;

        default:
            newt = ty;
            break;
    }
	return newt;
}
int
closeLazyUploadBufferedFile (const char *path) {
    int status;
    char iRODSPath[MAX_NAME_LEN];
    char bufferPath[MAX_NAME_LEN];
    lazyUploadFileInfo_t *lazyUploadFileInfo = NULL;

    // convert input path to iRODSPath
    status = _getiRODSPath(path, iRODSPath);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "closeLazyUploadBufferedFile: failed to get iRODS path - %s", path);
        return status;
    }

    status = _getBufferPath(iRODSPath, bufferPath);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "closeLazyUploadBufferedFile: failed to get Buffered lazy upload file path - %s", iRODSPath);
        return status;
    }

    LOCK(LazyUploadLock);
    
    // remove buffered file
    unlink(bufferPath);

    lazyUploadFileInfo = (lazyUploadFileInfo_t *)lookupFromHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath);
    if(lazyUploadFileInfo != NULL) {
        // has lazy-upload file handle opened
        if(lazyUploadFileInfo->localHandle > 0) {
            close(lazyUploadFileInfo->localHandle);
            lazyUploadFileInfo->localHandle = -1;
            rodsLog (LOG_DEBUG, "closeLazyUploadBufferedFile: close lazy-upload Buffered file handle - %s", iRODSPath);
        }

	    deleteFromHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath);

        if(lazyUploadFileInfo->path != NULL) {
            free(lazyUploadFileInfo->path);
            lazyUploadFileInfo->path = NULL;
        }

        free(lazyUploadFileInfo);
    }
    
    UNLOCK(LazyUploadLock);
    rodsLog (LOG_DEBUG, "closeLazyUploadBufferedFile: closed lazy-upload cache handle - %s", iRODSPath);
    return status;
}
static int
_isLazyUploadFile(const char *iRODSPath) {
    lazyUploadFileInfo_t *lazyUploadFileInfo = NULL;

    if (iRODSPath == NULL) {
        rodsLog (LOG_DEBUG, "_isLazyUploadFile: input inPath is NULL");
        return (SYS_INTERNAL_NULL_INPUT_ERR);
    }

    lazyUploadFileInfo = (lazyUploadFileInfo_t *)lookupFromHashTable(LazyUploadBufferedFileTable_Opened, (char *) iRODSPath);
    if (lazyUploadFileInfo == NULL) {
        return -1;
    }

    return (0);
}
void appendRuleIntoExtIndex(RuleDesc *rule, int i, Region *r) {
	FunctionDesc *fd = (FunctionDesc *)lookupFromHashTable(ruleEngineConfig.extFuncDescIndex->current, RULE_NAME(rule->node));
	RuleIndexList *rd;
	if(fd == NULL) {
		rd = newRuleIndexList(RULE_NAME(rule->node), i, r);
		fd = newRuleIndexListFD(rd, NULL, r);

		insertIntoHashTable(ruleEngineConfig.extFuncDescIndex->current, RULE_NAME(rule->node), fd);
	} else {
		if(getNodeType(fd)==N_FD_RULE_INDEX_LIST) {
			rd = FD_RULE_INDEX_LIST(fd);
			appendRuleNodeToRuleIndexList(rd, i ,r);
		} else if(getNodeType(fd) == N_FD_EXTERNAL) {
			/* combine N_FD_EXTERNAL with N_FD_RULE_LIST */
			updateInHashTable(ruleEngineConfig.extFuncDescIndex->current, RULE_NAME(rule->node), newRuleIndexListFD(newRuleIndexList(RULE_NAME(rule->node), i, r),fd->exprType, r));
		} else {
			/* todo error handling */
		}
	}
}
int
closePreloadedFile (const char *path) {
    int status;
    char iRODSPath[MAX_NAME_LEN];
    preloadFileHandleInfo_t *preloadFileHandleInfo = NULL;
    preloadFileHandleInfo_t *tmpPreloadFileHandleInfo = NULL;

    status = _getiRODSPath(path, iRODSPath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "closePreloadedFile: _getiRODSPath error.");
        rodsLog (LOG_ERROR, "closePreloadedFile: failed to get iRODS path - %s", path);
        return status;
    }

    LOCK(PreloadLock);

    preloadFileHandleInfo = (preloadFileHandleInfo_t *)lookupFromHashTable(PreloadFileHandleTable, iRODSPath);
    if(preloadFileHandleInfo != NULL) {
        // has preload file handle opened
        if(preloadFileHandleInfo->handle > 0) {
            close(preloadFileHandleInfo->handle);
            preloadFileHandleInfo->handle = -1;
            rodsLog (LOG_DEBUG, "closePreloadedFile: close preloaded cache handle - %s", iRODSPath);
        }

        if(preloadFileHandleInfo->path != NULL) {
            free(preloadFileHandleInfo->path);
            preloadFileHandleInfo->path = NULL;
        }
    
        // remove from hash table
        tmpPreloadFileHandleInfo = (preloadFileHandleInfo_t *)deleteFromHashTable(PreloadFileHandleTable, iRODSPath);
        if(tmpPreloadFileHandleInfo != NULL) {
            free(tmpPreloadFileHandleInfo);
        }
    }
    
    UNLOCK(PreloadLock);

    return status;
}
int
preloadFile (const char *path, struct stat *stbuf) {
    int status;
    preloadThreadInfo_t *existingThreadInfo = NULL;
    preloadThreadInfo_t *threadInfo = NULL;
    preloadThreadData_t *threadData = NULL;
    char iRODSPath[MAX_NAME_LEN];
    off_t cacheSize;

    // convert input path to iRODSPath
    status = _getiRODSPath(path, iRODSPath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "preloadFile: _getiRODSPath error.");
        rodsLog (LOG_ERROR, "preloadFile: failed to get iRODS path - %s", path);
        return status;
    }

    // check the given file is already preloaded or preloading
    LOCK(PreloadLock);

    // check the given file is preloading
    existingThreadInfo = (preloadThreadInfo_t *)lookupFromHashTable(PreloadThreadTable, iRODSPath);
    if(existingThreadInfo != NULL) {
        rodsLog (LOG_DEBUG, "preloadFile: preloading is already running - %s", iRODSPath);
        UNLOCK(PreloadLock);
        return 0;
    }

    if(_hasValidCache(iRODSPath, stbuf) != 0) {
        // invalidate cache - this may fail if cache file does not exists
        // if old cache exists in local, invalidate it
        _invalidateCache(iRODSPath);

        if(stbuf->st_size < PreloadConfig.preloadMinSize) {
            rodsLog (LOG_DEBUG, "preloadFile: given file is smaller than preloadMinSize, canceling preloading - %s", iRODSPath);
            UNLOCK(PreloadLock);
            return (0);
        }

        // check whether preload cache exceeds limit
        if(PreloadConfig.cacheMaxSize > 0) {
            // cache max size is set
            if(stbuf->st_size > (off_t)PreloadConfig.cacheMaxSize) {
                rodsLog (LOG_DEBUG, "preloadFile: given file is bigger than cacheMaxSize, canceling preloading - %s", iRODSPath);
                UNLOCK(PreloadLock);
                return (0);
            }

            cacheSize = getFileSizeRecursive(PreloadConfig.cachePath);
            if((cacheSize + stbuf->st_size) > (off_t)PreloadConfig.cacheMaxSize) {
                // evict?
                status = _evictOldCache((cacheSize + stbuf->st_size) - (off_t)PreloadConfig.cacheMaxSize);
                if(status < 0) {
                    rodsLog (LOG_ERROR, "preloadFile: failed to evict old cache");
                    UNLOCK(PreloadLock);
                    return status;
                }
            }
        }

        // does not have valid cache. now, start a new preloading

        // create a new thread to preload
        threadInfo = (preloadThreadInfo_t *)malloc(sizeof(preloadThreadInfo_t));
        threadInfo->path = strdup(iRODSPath);
        threadInfo->running = PRELOAD_THREAD_RUNNING;
        INIT_STRUCT_LOCK((*threadInfo));

        insertIntoHashTable(PreloadThreadTable, iRODSPath, threadInfo);

        // prepare thread argument
        threadData = (preloadThreadData_t *)malloc(sizeof(preloadThreadData_t));
        threadData->path = strdup(iRODSPath);
        memcpy(&threadData->stbuf, stbuf, sizeof(struct stat));
        threadData->threadInfo = threadInfo;

        rodsLog (LOG_DEBUG, "preloadFile: start preloading - %s", iRODSPath);
#ifdef USE_BOOST
        status = threadInfo->thread = new boost::thread(_preloadThread, (void *)threadData);
#else
        status = pthread_create(&threadInfo->thread, NULL, _preloadThread, (void *)threadData);
#endif
    } else {
        rodsLog (LOG_DEBUG, "preloadFile: given file is already preloaded - %s", iRODSPath);
        status = 0;
    }

    UNLOCK(PreloadLock);
    return status;
}
Exemple #14
0
int processXMsg( int streamId, char *readmsg,
                 RuleEngineEventParam *param, Node *node,
                 Env *env, ruleExecInfo_t *rei ) {

    char myhdr[HEADER_TYPE_LEN];
    char mymsg[MAX_NAME_LEN];
    char *outStr = NULL;
    int i, n;
    int iLevel, wCnt;
    int  ruleInx = 0;
    Region *r;
    Res *res;
    rError_t errmsg;
    errmsg.len = 0;
    errmsg.errMsg = NULL;
    r = make_region( 0, NULL );
    ParserContext *context = newParserContext( &errmsg, r );
    Pointer *e = newPointer2( readmsg );
    int rulegen = 1;
    int found;
    int grdf[2];
    int cmd = 0;
    int smallW;

    snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug:%s", param->actionName );
    memset( mymsg, 0, sizeof( mymsg ) );

    PARSER_BEGIN( DbgCmd )
    TRY( DbgCmd )
    TTEXT2( "n", "next" );
    cmd = REDEBUG_STEP_OVER;
    OR( DbgCmd )
    TTEXT2( "s", "step" );
    cmd = REDEBUG_NEXT;
    OR( DbgCmd )
    TTEXT2( "f", "finish" );
    cmd = REDEBUG_STEP_OUT;
    OR( DbgCmd )
    TTEXT2( "b", "break" );
    TRY( Param )
    TTYPE( TK_TEXT );
    int breakPointsInx2;
    for ( breakPointsInx2 = 0; breakPointsInx2 < 100; breakPointsInx2++ ) {
        if ( breakPoints[breakPointsInx2].actionName == NULL ) {
            break;
        }
    }
    if ( breakPointsInx2 == 100 ) {
        _writeXMsg( streamId, myhdr, "Maximum breakpoint count reached. Breakpoint not set.\n" );
        cmd = REDEBUG_WAIT;
    }
    else {
        breakPoints[breakPointsInx2].actionName = strdup( token->text );
        char * base_ptr = NULL;
        TRY( loc )
        TTYPE( TK_TEXT );
        base_ptr = ( char * ) malloc( sizeof( token->text ) + 2 );
        base_ptr[0] = 'f';
        strcpy( base_ptr + 1, token->text );
        TTEXT( ":" );
        TTYPE( TK_INT );
        breakPoints[breakPointsInx2].base = strdup( base_ptr );
        breakPoints[breakPointsInx2].line = atoi( token->text );
        rodsLong_t range[2];
        char rulesFileName[MAX_NAME_LEN];
        getRuleBasePath( base_ptr, rulesFileName );

        FILE *file;
        /* char errbuf[ERR_MSG_LEN]; */
        file = fopen( rulesFileName, "r" );
        if ( file == NULL ) {
            free( context );
            deletePointer( e );
            free( base_ptr );
            return RULES_FILE_READ_ERROR;
        }
        Pointer *p = newPointer( file, base_ptr );


        if ( getLineRange( p, breakPoints[breakPointsInx2].line, range ) == 0 ) {
            breakPoints[breakPointsInx2].start = range[0];
            breakPoints[breakPointsInx2].finish = range[1];
        }
        else {
            breakPoints[breakPointsInx2].actionName = NULL;
        }
        deletePointer( p );
        OR( loc )
        TTYPE( TK_INT );
        if ( node != NULL ) {
            breakPoints[breakPointsInx2].base = strdup( node->base );
            breakPoints[breakPointsInx2].line = atoi( token->text );
            rodsLong_t range[2];
            Pointer *p = newPointer2( breakPoints[breakPointsInx2].base );
            if ( getLineRange( p, breakPoints[breakPointsInx2].line, range ) == 0 ) {
                breakPoints[breakPointsInx2].start = range[0];
                breakPoints[breakPointsInx2].finish = range[1];
            }
            else {
                breakPoints[breakPointsInx2].actionName = NULL;
            }
            deletePointer( p );
        }
        else {
            breakPoints[breakPointsInx2].actionName = NULL;
        }
        OR( loc )
        /* breakPoints[breakPointsInx].base = NULL; */
        END_TRY( loc )

        free( base_ptr );
        if ( breakPoints[breakPointsInx2].actionName != NULL )
            snprintf( mymsg, MAX_NAME_LEN, "Breakpoint %i  set at %s\n", breakPointsInx2,
                      breakPoints[breakPointsInx2].actionName );
        else {
            snprintf( mymsg, MAX_NAME_LEN, "Cannot set breakpoint, source not available\n" );
        }
        _writeXMsg( streamId, myhdr, mymsg );
        if ( breakPointsInx <= breakPointsInx2 ) {
            breakPointsInx = breakPointsInx2 + 1;
        }
        cmd = REDEBUG_WAIT;
    }
    OR( Param )
    NEXT_TOKEN_BASIC;
    _writeXMsg( streamId, myhdr, "Unknown parameter type.\n" );
    cmd = REDEBUG_WAIT;
    OR( Param )
    _writeXMsg( streamId, myhdr, "Debugger command \'break\' requires at least one argument.\n" );
    cmd = REDEBUG_WAIT;
    END_TRY( Param )

    OR( DbgCmd )
    TRY( Where )
    TTEXT2( "w", "where" );
    smallW = 1;
    OR( Where )
    TTEXT2( "W", "Where" );
    smallW = 0;
    END_TRY( Where )
    wCnt = 20;
    OPTIONAL_BEGIN( Param )
    TTYPE( TK_INT );
    wCnt = atoi( token->text );
    OPTIONAL_END( Param )
    iLevel = 0;

    i = reDebugStackCurrPtr - 1;
    while ( i >= 0 && wCnt > 0 ) {
        if ( !smallW || ( reDebugPCType( ( RuleEngineEvent ) reDebugStackCurr[i].label ) & 1 ) != 0 ) {
            snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Level %3i", iLevel );
            char msg[HEADER_TYPE_LEN - 1];
            RuleEngineEventParam param;
            param.ruleIndex = 0;
            param.actionName = reDebugStackCurr[i].step;
            printRuleEngineEventLabel( msg, HEADER_TYPE_LEN - 1, ( RuleEngineEvent ) reDebugStackCurr[i].label, &param );
            _writeXMsg( streamId,  myhdr, msg );
            if ( reDebugStackCurr[i].label != EXEC_ACTION_BEGIN ) {
                iLevel++;
            }
            wCnt--;
        }
        i--;
    }
    OR( DbgCmd )
    TTEXT2( "l", "list" );
    TRY( Param )
    TTEXT2( "r", "rule" );
    TRY( ParamParam )
    TTYPE( TK_TEXT );

    mymsg[0] = '\n';
    mymsg[1] = '\0';
    snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Listing %s", token->text );
    RuleIndexListNode *node;
    found = 0;
    while ( findNextRule2( token->text, ruleInx, &node ) != NO_MORE_RULES_ERR ) {
        found = 1;
        if ( node->secondaryIndex ) {
            n = node->condIndex->valIndex->len;
            int i;
            for ( i = 0; i < n; i++ ) {
                Bucket *b = node->condIndex->valIndex->buckets[i];
                while ( b != NULL ) {
                    RuleDesc *rd = getRuleDesc( *( int * )b->value );
                    char buf[MAX_RULE_LEN];
                    ruleToString( buf, MAX_RULE_LEN, rd );
                    snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "%i: %s\n%s\n", node->ruleIndex, rd->node->base[0] == 's' ? "<source>" : rd->node->base + 1, buf );
                    b = b->next;
                }
            }
        }
        else {
            RuleDesc *rd = getRuleDesc( node->ruleIndex );
            char buf[MAX_RULE_LEN];
            ruleToString( buf, MAX_RULE_LEN, rd );
            snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "\n  %i: %s\n%s\n", node->ruleIndex, rd->node->base[0] == 's' ? "<source>" : rd->node->base + 1, buf );
        }
        ruleInx ++;
    }
    if ( !found ) {
        snprintf( mymsg, MAX_NAME_LEN, "Rule %s not found\n", token->text );
    }
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    OR( ParamParam )
    _writeXMsg( streamId, myhdr, "Debugger command \'list rule\' requires one argument.\n" );
    cmd = REDEBUG_WAIT;
    END_TRY( ParamParam )
    OR( Param )
    TTEXT2( "b", "breakpoints" );
    snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Listing %s", token->text );
    mymsg[0] = '\n';
    mymsg[1] = '\0';
    for ( i = 0; i < breakPointsInx; i++ ) {
        if ( breakPoints[i].actionName != NULL ) {
            if ( breakPoints[i].base != NULL ) {
                snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "Breaking at BreakPoint %i:%s %s:%d\n", i , breakPoints[i].actionName, breakPoints[i].base[0] == 's' ? "<source>" : breakPoints[i].base + 1, breakPoints[i].line );
            }
            else {
                snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "Breaking at BreakPoint %i:%s\n", i , breakPoints[i].actionName );
            }
        }
    }
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    OR( Param )
    TTEXT( "*" );
    snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Listing %s", token->text );
    Env *cenv = env;
    mymsg[0] = '\n';
    mymsg[1] = '\0';
    found = 0;
    while ( cenv != NULL ) {
        n = cenv->current->size;
        for ( i = 0; i < n; i++ ) {
            Bucket *b = cenv->current->buckets[i];
            while ( b != NULL ) {
                if ( b->key[0] == '*' ) { /* skip none * variables */
                    found = 1;
                    char typeString[128];
                    typeToString( ( ( Res * )b->value )->exprType, NULL, typeString, 128 );
                    snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "%s of type %s\n", b->key, typeString );
                }
                b = b->next;
            }
        }
        cenv = cenv->previous;
    }
    if ( !found ) {
        snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "<empty>\n" );
    }
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    OR( Param )
    syncTokenQueue( e, context );
    skipWhitespace( e );
    ABORT( lookAhead( e, 0 ) != '$' );
    snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Listing %s", token->text );
    mymsg[0] = '\n';
    mymsg[1] = '\0';
    Hashtable *vars = newHashTable( 100 );
    for ( i = 0; i < coreRuleVarDef .MaxNumOfDVars; i++ ) {
        if ( lookupFromHashTable( vars, coreRuleVarDef.varName[i] ) == NULL ) {
            snprintf( &mymsg[strlen( mymsg )], MAX_NAME_LEN - strlen( mymsg ), "$%s\n", coreRuleVarDef.varName[i] );
            insertIntoHashTable( vars, coreRuleVarDef.varName[i], coreRuleVarDef.varName[i] );
        }
    }
    deleteHashTable( vars, NULL );
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    OR( Param )
    NEXT_TOKEN_BASIC;
    _writeXMsg( streamId, myhdr, "Unknown parameter type.\n" );
    cmd = REDEBUG_WAIT;
    OR( Param )
    _writeXMsg( streamId, myhdr, "Debugger command \'list\' requires at least one argument.\n" );
    cmd = REDEBUG_WAIT;
    END_TRY( Param )
    OR( DbgCmd )
    TTEXT2( "c", "continue" );
    cmd = REDEBUG_STEP_CONTINUE;
    OR( DbgCmd )
    TTEXT2( "C", "Continue" );
    cmd = REDEBUG_CONTINUE_VERBOSE;
    OR( DbgCmd )
    TTEXT2( "del", "delete" );
    TRY( Param )
    TTYPE( TK_INT );
    n = atoi( token->text );
    if ( breakPoints[n].actionName != NULL ) {
        free( breakPoints[n].actionName );
        if ( breakPoints[n].base != NULL ) {
            free( breakPoints[n].base );
        }
        breakPoints[n].actionName = NULL;
        breakPoints[n].base = NULL;
        snprintf( mymsg, MAX_NAME_LEN, "Breakpoint %i  deleted\n", n );
    }
    else {
        snprintf( mymsg, MAX_NAME_LEN, "Breakpoint %i  has not been defined\n", n );
    }
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    OR( Param )
    _writeXMsg( streamId, myhdr, "Debugger command \'delete\' requires one argument.\n" );
    cmd = REDEBUG_WAIT;
    END_TRY( Param )
    OR( DbgCmd )
    TTEXT2( "p", "print" );
    Node *n = parseTermRuleGen( e, 1, context );
    if ( getNodeType( n ) == N_ERROR ) {
        errMsgToString( context->errmsg, mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ) );
    }
    else {
        snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug: Printing " );
        char * ptr = myhdr + strlen( myhdr );
        i = HEADER_TYPE_LEN - 1 - strlen( myhdr );
        termToString( &ptr, &i, 0, MIN_PREC, n, 0 );
        snprintf( ptr, i, "\n" );
        if ( env != NULL ) {
            disableReDebugger( grdf );
            res = computeNode( n, NULL, regionRegionCpEnv( env, r, ( RegionRegionCopyFuncType * ) regionRegionCpNode ), rei, 0, &errmsg, r );
            enableReDebugger( grdf );
            outStr = convertResToString( res );
            snprintf( mymsg, MAX_NAME_LEN, "%s\n", outStr );
            free( outStr );
            if ( getNodeType( res ) == N_ERROR ) {
                errMsgToString( &errmsg, mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ) );
            }
        }
        else {
            snprintf( mymsg, MAX_NAME_LEN, "Runtime environment: <empty>\n" );
        }
    }
    _writeXMsg( streamId, myhdr, mymsg );

    cmd = REDEBUG_WAIT;
    OR( DbgCmd )
    TTEXT2( "d", "discontinue" );
    cmd = REDEBUG_WAIT;
    OR( DbgCmd )
    snprintf( mymsg, MAX_NAME_LEN, "Unknown Action: %s", readmsg );
    _writeXMsg( streamId, myhdr, mymsg );
    cmd = REDEBUG_WAIT;
    END_TRY( DbgCmd )
    PARSER_END( DbgCmd )
    freeRErrorContent( &errmsg );
    region_free( r );
    deletePointer( e );
    free( context );
    return cmd;
}
int
writeLazyUploadBufferedFile (const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
    int status;
    lazyUploadFileInfo_t *lazyUploadFileInfo = NULL;
    char iRODSPath[MAX_NAME_LEN];
    char bufferPath[MAX_NAME_LEN];
    off_t seek_status;
    int descInx;

    // convert input path to iRODSPath
    status = _getiRODSPath(path, iRODSPath);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "writeLazyUploadBufferedFile: failed to get iRODS path - %s", path);
        return status;
    }

    status = _getBufferPath(iRODSPath, bufferPath);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "writeLazyUploadBufferedFile: failed to get buffer path - %s", iRODSPath);
        return status;
    }

    LOCK(LazyUploadLock);

    // check the given file is Buffered
    lazyUploadFileInfo = (lazyUploadFileInfo_t *)lookupFromHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath);
    if(lazyUploadFileInfo != NULL) {
        // has lazy upload file handle opened
        if(lazyUploadFileInfo->localHandle < 0) {
            rodsLog (LOG_DEBUG, "writeLazyUploadBufferedFile: wrong file descriptor - %s, %d", iRODSPath, lazyUploadFileInfo->localHandle);
            UNLOCK(LazyUploadLock);
            return -EBADF;
        }
    } else {
        rodsLog (LOG_DEBUG, "writeLazyUploadBufferedFile: file is not opened - %s", iRODSPath);
        UNLOCK(LazyUploadLock);
        return -EBADF;
    }

    if(offset - lazyUploadFileInfo->curLocalOffsetStart < 0) {
        // backward?
        // commit local buffered data
        status = _commitLocalBuffer(iRODSPath, fi, lazyUploadFileInfo);
        if(status < 0) {
            rodsLog (LOG_DEBUG, "writeLazyUploadBufferedFile: failed to commit local buffered data - %s", iRODSPath);
            UNLOCK(LazyUploadLock);
            return status; 
        }

        // rewrite directly to iRODS
        descInx = GET_IFUSE_DESC_INDEX(fi);

        if (checkFuseDesc (descInx) < 0) {
            UNLOCK(LazyUploadLock);
            return -EBADF;
        }

        status = _ifuseWrite (&IFuseDesc[descInx], (char *)buf, size, offset);
        unlockDesc (descInx);
        UNLOCK(LazyUploadLock);
        return status;
    }

    // try to write to local buffer
    seek_status = lseek (lazyUploadFileInfo->localHandle, offset - lazyUploadFileInfo->curLocalOffsetStart, SEEK_SET);
    if (seek_status != (offset - lazyUploadFileInfo->curLocalOffsetStart)) {
        status = (int)seek_status;
        rodsLog (LOG_DEBUG, "writeLazyUploadBufferedFile: failed to seek file desc - %d, %ld -> %ld", lazyUploadFileInfo->localHandle, offset - lazyUploadFileInfo->curLocalOffsetStart, seek_status);
        UNLOCK(LazyUploadLock);
        return status;
    }

    // TEST
    //if (lazyUploadFileInfo->curOffset > 10*1024*1024) {
    //    status = -1;
    //   errno = ENOSPC;
    //} else {
    //    status = write (lazyUploadFileInfo->localHandle, buf, size);
    //}
    // TEST END

    status = write (lazyUploadFileInfo->localHandle, buf, size);
    rodsLog (LOG_DEBUG, "writeLazyUploadBufferedFile: write to opened lazy-upload Buffered file - %d", lazyUploadFileInfo->localHandle);

    if (status < 0) {
        // no space?
        if (errno == ENOSPC) {
            // handle no space
            // mode switch
            status = _commitLocalBuffer(iRODSPath, fi, lazyUploadFileInfo);
            if(status < 0) {
                rodsLog (LOG_DEBUG, "writeLazyUploadBufferedFile: failed to change to appending mode - %s", iRODSPath);
                UNLOCK(LazyUploadLock);
                return status; 
            }

            // write to local buffer again
            seek_status = lseek (lazyUploadFileInfo->localHandle, offset - lazyUploadFileInfo->curLocalOffsetStart, SEEK_SET);
            if (seek_status != (offset - lazyUploadFileInfo->curLocalOffsetStart)) {
                status = (int)seek_status;
                rodsLog (LOG_DEBUG, "writeLazyUploadBufferedFile: failed to seek file desc - %d, %ld -> %ld", lazyUploadFileInfo->localHandle, offset - lazyUploadFileInfo->curLocalOffsetStart, seek_status);
                UNLOCK(LazyUploadLock);
                return status;
            }

            status = write (lazyUploadFileInfo->localHandle, buf, size);
            rodsLog (LOG_DEBUG, "writeLazyUploadBufferedFile: write to opened lazy-upload Buffered file - %d", lazyUploadFileInfo->localHandle);

            if(status >= 0) {
                lazyUploadFileInfo->curOffset += status;
            }
        }
    } else {
        lazyUploadFileInfo->curOffset += status;
    }

    UNLOCK(LazyUploadLock);

    return status;
}
int
openPreloadedFile (const char *path) {
    int status;
    char iRODSPath[MAX_NAME_LEN];
    char preloadCachePath[MAX_NAME_LEN];
    preloadFileHandleInfo_t *preloadFileHandleInfo = NULL;
    int desc;

    status = _getiRODSPath(path, iRODSPath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "openPreloadedFile: _getiRODSPath error.");
        rodsLog (LOG_ERROR, "openPreloadedFile: failed to get iRODS path - %s", path);
        return status;
    }

    status = _getCachePath(iRODSPath, preloadCachePath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "openPreloadedFile: _getCachePath error.");
        rodsLog (LOG_ERROR, "openPreloadedFile: failed to get cache path - %s", path);
        return status;
    }

    LOCK(PreloadLock);

    desc = -1;

    preloadFileHandleInfo = (preloadFileHandleInfo_t *)lookupFromHashTable(PreloadFileHandleTable, iRODSPath);
    if(preloadFileHandleInfo != NULL) {
        // has preload file handle opened
        if(preloadFileHandleInfo->handle > 0) {
            // reuse handle
            desc = preloadFileHandleInfo->handle;
            rodsLog (LOG_DEBUG, "openPreloadedFile: file is already opened - %s", iRODSPath);
        } else {
            // reuse handleinfo
            if(_hasCache(iRODSPath) >= 0) {
                desc = open (preloadCachePath, O_RDONLY);

                if(desc > 0) {
                    preloadFileHandleInfo->handle = desc;
                    rodsLog (LOG_DEBUG, "openPreloadedFile: opens a file handle - %s", iRODSPath);
                }
            }
        }
    } else {
        // if preloaded cache file is not opened
        // open new
        if(_hasCache(iRODSPath) >= 0) {
            desc = open (preloadCachePath, O_RDONLY);
            rodsLog (LOG_DEBUG, "openPreloadedFile: open a preloaded cache path - %s", iRODSPath);

            if(desc > 0) {
                preloadFileHandleInfo = (preloadFileHandleInfo_t *)malloc(sizeof(preloadFileHandleInfo_t));
                preloadFileHandleInfo->path = strdup(iRODSPath);
                preloadFileHandleInfo->handle = desc;
                INIT_STRUCT_LOCK((*preloadFileHandleInfo));

                insertIntoHashTable(PreloadFileHandleTable, iRODSPath, preloadFileHandleInfo);
            }
        }
    }

    UNLOCK(PreloadLock);

    return desc;
}
Exemple #17
0
ExprType *typeRuleSet( RuleSet *ruleset, rError_t *errmsg, Node **errnode, Region *r ) {
    Env *funcDesc = ruleEngineConfig.extFuncDescIndex;
    Hashtable *ruleType = newHashTable2( MAX_NUM_RULES * 2, r );
    ExprType *res;
    int i;
    for ( i = 0; i < ruleset->len; i++ ) {
        RuleDesc *rule = ruleset->rules[i];
        if ( rule->ruleType == RK_REL || rule->ruleType == RK_FUNC ) {
            List *typingConstraints = newList( r );
            Hashtable *varTypes = newHashTable2( 100, r );
            ExprType *restype = typeRule( rule, funcDesc, varTypes, typingConstraints, errmsg, errnode, r );
            /*char buf[1024]; */
            /*typingConstraintsToString(typingConstraints, buf, 1024); */
            /*printf("rule %s, typing constraints: %s\n", ruleset->rules[i]->subtrees[0]->text, buf); */
            if ( getNodeType( restype ) == T_ERROR ) {
                res = restype;
                char *errbuf = ( char * ) malloc( ERR_MSG_LEN * 1024 * sizeof( char ) );
                errMsgToString( errmsg, errbuf, ERR_MSG_LEN * 1024 );
#ifdef DEBUG
                writeToTmp( "ruleerr.log", errbuf );
                writeToTmp( "ruleerr.log", "\n" );
#endif
                rodsLog( LOG_ERROR, "%s", errbuf );
                free( errbuf );
                freeRErrorContent( errmsg );
                RETURN;
            }
            /* check that function names are unique and do not conflict with system msis */
            char errbuf[ERR_MSG_LEN];
            char *ruleName = rule->node->subtrees[0]->text;
            FunctionDesc *fd;
            if ( ( fd = ( FunctionDesc * )lookupFromEnv( funcDesc, ruleName ) ) != NULL ) {
                if ( getNodeType( fd ) != N_FD_EXTERNAL && getNodeType( fd ) != N_FD_RULE_INDEX_LIST ) {
                    char *err;
                    switch ( getNodeType( fd ) ) {
                    case N_FD_CONSTRUCTOR:
                        err = "redefinition of constructor";
                        break;
                    case N_FD_DECONSTRUCTOR:
                        err = "redefinition of deconstructor";
                        break;
                    case N_FD_FUNCTION:
                        err = "redefinition of system microservice";
                        break;
                    default:
                        err = "redefinition of system symbol";
                        break;
                    }

                    generateErrMsg( err, NODE_EXPR_POS( rule->node ), rule->node->base, errbuf );
                    addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf );
                    res = newErrorType( RE_FUNCTION_REDEFINITION, r );
                    *errnode = rule->node;
                    RETURN;
                }
            }

            RuleDesc *rd = ( RuleDesc * )lookupFromHashTable( ruleType, ruleName );
            if ( rd != NULL ) {
                if ( rule->ruleType == RK_FUNC || rd ->ruleType == RK_FUNC ) {
                    generateErrMsg( "redefinition of function", NODE_EXPR_POS( rule->node ), rule->node->base, errbuf );
                    addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf );
                    generateErrMsg( "previous definition", NODE_EXPR_POS( rd->node ), rd->node->base, errbuf );
                    addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf );
                    res = newErrorType( RE_FUNCTION_REDEFINITION, r );
                    *errnode = rule->node;
                    RETURN;
                }
            }
            else {
                insertIntoHashTable( ruleType, ruleName, rule );
            }
        }
    }
    res = newSimpType( T_INT, r ); /* Although a rule set does not have type T_INT, return T_INT to indicate success. */

ret:
    return res;
}
int
openLazyUploadBufferedFile(const char *path, int accmode) {
    int status;
    lazyUploadFileInfo_t *lazyUploadFileInfo = NULL;
    char iRODSPath[MAX_NAME_LEN];
    char bufferPath[MAX_NAME_LEN];
    int desc;

    // convert input path to iRODSPath
    status = _getiRODSPath(path, iRODSPath);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: failed to get iRODS path - %s", path);
        return status;
    }

    status = _getBufferPath(iRODSPath, bufferPath);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: failed to get buffer path - %s", iRODSPath);
        return status;
    }

    LOCK(LazyUploadLock);

    desc = -1;

    // check the given file is Buffered
    lazyUploadFileInfo = (lazyUploadFileInfo_t *)lookupFromHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath);
    if(lazyUploadFileInfo != NULL) {
        // has lazy upload file opened
        rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: same file is already opened for lazy-upload - %s", iRODSPath);
        UNLOCK(LazyUploadLock);
        return -EMFILE;
    }

    lazyUploadFileInfo = (lazyUploadFileInfo_t *)lookupFromHashTable(LazyUploadBufferedFileTable_Created, iRODSPath);
    if(lazyUploadFileInfo != NULL) {
        // has lazy upload file handle opened
        if(lazyUploadFileInfo->localHandle > 0) {
            rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: same file is already opened for lazy-upload - %s", iRODSPath);
            UNLOCK(LazyUploadLock);
            return -EMFILE;
        } else {
            // update file handle and access mode
            desc = open (bufferPath, O_RDWR|O_CREAT|O_TRUNC, 0755);

            if(desc > 0) {
                lazyUploadFileInfo->accmode = accmode;
                lazyUploadFileInfo->localHandle = desc;
                rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: opens a file handle - %s", iRODSPath);

                // move to opened hashtable
                deleteFromHashTable(LazyUploadBufferedFileTable_Created, iRODSPath);
                insertIntoHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath, lazyUploadFileInfo);
            }
        }
    } else {
        rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: mknod is not called before opening - %s", iRODSPath);
        UNLOCK(LazyUploadLock);
        return -EBADF;
    }

    UNLOCK(LazyUploadLock);

    return desc;
}