예제 #1
0
int
readXMsg( msParam_t* inStreamId, msParam_t *inCondRead,
          msParam_t *outMsgNum, msParam_t *outSeqNum,
          msParam_t *outHdr, msParam_t *outMsg,
          msParam_t *outUser, msParam_t *outAddr, ruleExecInfo_t *rei ) {
    int i;
    int sNum = 0;
    int mNum = 0;
    char *hdr = NULL;
    char *msg = NULL;
    char *user = NULL;
    char *addr = NULL;
    int streamId;
    xmsgTicketInfo_t *xmsgTicketInfo;
    char *condRead = NULL;
    RE_TEST_MACRO( "    Calling readXMsg" );

    if ( !strcmp( inStreamId->type, XmsgTicketInfo_MS_T ) ) {
        xmsgTicketInfo = ( xmsgTicketInfo_t * ) inStreamId->inOutStruct;
        streamId = xmsgTicketInfo->rcvTicket;
    }
    else if ( !strcmp( inStreamId->type, STR_MS_T ) ) {
        streamId = ( int ) atoi( ( char* )inStreamId->inOutStruct );
    }
    else {
        streamId = CAST_PTR_INT  inStreamId->inOutStruct;
    }
    condRead = ( char * ) inCondRead->inOutStruct;
    i = _readXMsg( streamId, condRead, &mNum, &sNum, &hdr, &msg, &user, &addr );
    if ( i >= 0 ) {
        outHdr->inOutStruct = ( void * ) hdr;
        outHdr->type = strdup( STR_MS_T );
        outMsg->inOutStruct = ( void * ) msg;
        outMsg->type = strdup( STR_MS_T );
        fillIntInMsParam( outMsgNum, mNum );
        fillIntInMsParam( outSeqNum, sNum );
        outUser->inOutStruct = ( void * ) user;
        outUser->type = strdup( STR_MS_T );
        outAddr->inOutStruct = ( void * ) addr;
        outAddr->type = strdup( STR_MS_T );

    }
    return i;
}
예제 #2
0
/*
 * label type of rule engine event
 * flag -4 log rei
 *      otherwise do not log rei
 * action
 *
 */
int
reDebug( RuleEngineEvent label, int flag, RuleEngineEventParam *param, Node *node, Env *env, ruleExecInfo_t *rei ) {
    /* do not log anything if logging is turned off */
    if ( ruleEngineConfig.logging == 0 ) {
        return 0;
    }
    int i, m, s, status, sleepT, j;
    int processedBreakPoint = 0;
    char hdr[HEADER_TYPE_LEN];
    char *readhdr = NULL;
    char *readmsg = NULL;
    char *user = NULL;
    char *addr = NULL;
    static int mNum = 0;
    static int sNum = 0;
    static int curStat = 0;
    static int reDebugStackPtr = -1;
    static int reDebugStopAt = 1;
    char condRead[MAX_NAME_LEN];
    char myActionStr[10][MAX_NAME_LEN + 10];
    int aNum = 0;
    char seActionStr[10 * MAX_NAME_LEN + 100];
    char timestamp[TIME_LEN];
    rsComm_t *svrComm;
    int waitCnt = 0;
    sleepT = 1;
    char buf[HEADER_TYPE_LEN - 1];

    svrComm = rei->rsComm;

    if ( svrComm == NULL ) {
        rodsLog( LOG_ERROR, "Empty svrComm in REI structure for actionStr=%s\n",
                 param->actionName );
        return 0;
    }

    generateLogTimestamp( timestamp, TIME_LEN );
    printRuleEngineEventLabel( buf, HEADER_TYPE_LEN - 1, label, param );
    snprintf( hdr, HEADER_TYPE_LEN - 1,   "iaudit:%s", timestamp );
    condRead[0] = '\0';
    /* rodsLog (LOG_NOTICE,"PPP:%s\n",hdr); */
    snprintf( seActionStr, MAX_NAME_LEN + 10, "%s", buf );
    if ( GlobalREAuditFlag > 0 ) {
        if ( flag == -4 ) {
            if ( rei->uoic != NULL && strlen( rei->uoic->userName ) > 0 && strlen( rei->uoic->rodsZone ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  USER:%s@%s", rei->uoic->userName, rei->uoic->rodsZone );
                aNum++;
            }
            if ( rei->doi != NULL && strlen( rei->doi->objPath ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  DATA:%s", rei->doi->objPath );
                aNum++;
            }
            if ( rei->doi != NULL && strlen( rei->doi->filePath ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  FILE:%s", rei->doi->filePath );
                aNum++;
            }
            if ( rei->doinp != NULL && strlen( rei->doinp->objPath ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  DATAIN:%s", rei->doinp->objPath );
                aNum++;
            }
            if ( rei->doi != NULL && strlen( rei->doi->rescName ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  RESC:%s", rei->doi->rescName );
                aNum++;
            }
            if ( rei->coi != NULL && strlen( rei->coi->collName ) > 0 ) {
                snprintf( myActionStr[aNum], MAX_NAME_LEN + 10 , "  COLL:%s", rei->coi->collName );
                aNum++;
            }
            for ( j = 0; j < aNum; j++ ) {
                strncat( seActionStr, myActionStr[j], 10 * MAX_NAME_LEN + 100 - strlen( seActionStr ) );
            }
        }
    }

    /* Write audit trail */
    if ( GlobalREAuditFlag == 3 ) {
        i = _writeXMsg( GlobalREAuditFlag, hdr, seActionStr );
        if ( i < 0 ) {
            irods::log( ERROR( i, "_writeXMsg failed." ) );
        }
    }


    /* Send current position for debugging */
    if ( GlobalREDebugFlag > 5 ) {
        /* modify stack */
        int pcType = reDebugPCType( label );
        if ( ( pcType & 1 ) != 0 ) {
            pushReStack( label, param->actionName );
        }
        else if ( ( pcType & 2 ) != 0 ) {
            popReStack( label, param->actionName );
        }

        if ( curStat == REDEBUG_CONTINUE && reDebugStackCurrPtr <= reDebugStackPtr && ( reDebugPCType( label ) & reDebugStopAt ) != 0 ) {
            curStat = REDEBUG_WAIT;
        }
        if ( curStat != REDEBUG_CONTINUE ) {
            snprintf( hdr, HEADER_TYPE_LEN - 1,   "idbug:%s", param->actionName );
            i = _writeXMsg( GlobalREDebugFlag, hdr, buf );
            if ( i < 0 ) {
                irods::log( ERROR( i, "_writeXMsg failed." ) );
            }
        }

        while ( GlobalREDebugFlag > 5 ) {
            s = sNum;
            m = mNum;
            /* what should be the condition */
            sprintf( condRead, "(*XSEQNUM >= %d) && (*XADDR != \"%s:%i\") && (*XUSER  == \"%s@%s\") && ((*XHDR == \"CMSG:ALL\") %%%% (*XHDR == \"CMSG:%s:%i\"))",
                     s, myHostName, myPID, svrComm->clientUser.userName, svrComm->clientUser.rodsZone, myHostName, myPID );

            /*
            sprintf(condRead, "(*XSEQNUM >= %d)  && ((*XHDR == CMSG:ALL) %%%% (*XHDR == CMSG:%s:%i))",
            	s,  myHostName, getpid());
            */
            status = _readXMsg( GlobalREDebugFlag, condRead, &m, &s, &readhdr, &readmsg, &user, &addr );
            if ( status == SYS_UNMATCHED_XMSG_TICKET ) {
                cleanUpDebug();
                return 0;
            }
            if ( status  >= 0 ) {
                rodsLog( LOG_NOTICE, "Getting XMsg:%i:%s:%s\n", s, readhdr, readmsg );
                curStat = processXMsg( GlobalREDebugFlag, readmsg,
                                       param, node, env, rei );
                if ( readhdr != NULL ) {
                    free( readhdr );
                }
                if ( readmsg != NULL ) {
                    free( readmsg );
                }
                if ( user != NULL ) {
                    free( user );
                }
                if ( addr != NULL ) {
                    free( addr );
                }

                mNum = m;
                sNum = s + 1;
                if ( curStat == REDEBUG_WAIT ) {
                    sendWaitXMsg( GlobalREDebugFlag );
                }
                else if ( curStat == REDEBUG_STEP_OVER ) {
                    reDebugStackPtr = reDebugStackCurrPtr;
                    reDebugStopAt = 1;
                    curStat = REDEBUG_CONTINUE;
                    break;
                }
                else if ( curStat == REDEBUG_STEP_OUT ) {
                    reDebugStackPtr = reDebugStackCurrPtr - 1;
                    reDebugStopAt = 2;
                    curStat = REDEBUG_CONTINUE;
                    break;
                }
                else if ( curStat == REDEBUG_STEP_CONTINUE ) {
                    reDebugStackPtr = -1;
                    curStat = REDEBUG_CONTINUE;
                    break;
                }
                else if ( curStat == REDEBUG_NEXT ) {
                    break;
                }
            }
            else {
                if ( !( curStat == REDEBUG_CONTINUE || curStat == REDEBUG_CONTINUE_VERBOSE ) ) {

                    /*#if _POSIX_C_SOURCE >= 199309L
                    					struct timespec time = {0, 100000000}, rem;
                    					nanosleep(&time, &rem);
                    					waitCnt+=10;
                    #else*/
                    sleep( sleepT );
                    waitCnt += 100;
                    /*#endif*/
                    if ( waitCnt > 6000 ) {
                        sendWaitXMsg( GlobalREDebugFlag );
                        waitCnt = 0;
                    }
                }
            }
            if ( curStat == REDEBUG_CONTINUE || curStat == REDEBUG_CONTINUE_VERBOSE ) {
                if ( processedBreakPoint == 1 ) {
                    break;
                }
                curStat = processBreakPoint( GlobalREDebugFlag,
                                             param, node, curStat );
                processedBreakPoint = 1;
                if ( curStat == REDEBUG_WAIT ) {
                    sendWaitXMsg( GlobalREDebugFlag );
                    continue;
                }
                else {
                    break;
                }
            }
        }
    }


    return 0;
}
예제 #3
0
int initializeReDebug( rsComm_t *svrComm ) {
    char condRead[NAME_LEN];
    int i, s, m, status;
    char *readhdr = NULL;
    char *readmsg = NULL;
    char *user = NULL;
    char *addr = NULL;

    if ( svrComm == NULL ) {
        return 0;
    }
    if ( GlobalREDebugFlag != 4 ) {
        return 0;
    }

    s = 0;
    m = 0;
    myPID = ( int ) getpid();
    myHostName[0] = '\0';
    gethostname( myHostName, MAX_NAME_LEN );
    sprintf( condRead, "(*XUSER  == \"%s@%s\") && (*XHDR == \"STARTDEBUG\")",
             svrComm->clientUser.userName, svrComm->clientUser.rodsZone );
    status = _readXMsg( GlobalREDebugFlag, condRead, &m, &s, &readhdr, &readmsg, &user, &addr );
    if ( status >= 0 ) {
        if ( ( readmsg != NULL )  && strlen( readmsg ) > 0 ) {
            GlobalREDebugFlag = atoi( readmsg );
        }
        if ( readhdr != NULL ) {
            free( readhdr );
        }
        if ( readmsg != NULL ) {
            free( readmsg );
        }
        if ( user != NULL ) {
            free( user );
        }
        if ( addr != NULL ) {
            free( addr );
        }
        /* initialize reDebug stack space*/
        for ( i = 0; i < REDEBUG_STACK_SIZE_FULL; i++ ) {
            reDebugStackFull[i] = NULL;
        }
        for ( i = 0; i < REDEBUG_STACK_SIZE_CURR; i++ ) {
            reDebugStackCurr[i].label = -1;
            reDebugStackCurr[i].step = NULL;
        }
        memset( breakPoints, 0, sizeof( struct Breakpoint ) * 100 );

        reDebugStackFullPtr = 0;
        reDebugStackCurrPtr = 0;
        snprintf( waitHdr, HEADER_TYPE_LEN - 1,   "idbug:" );

        rodsLog( LOG_NOTICE, "reDebugInitialization: Got Debug StreamId:%i\n", GlobalREDebugFlag );
        snprintf( waitMsg, MAX_NAME_LEN, "PROCESS BEGIN at %s:%i. Client connected from %s at port %i\n",
                  myHostName, myPID, svrComm->clientAddr, ntohs( svrComm->localAddr.sin_port ) );
        _writeXMsg( GlobalREDebugFlag, "idbug", waitMsg );
        snprintf( waitMsg, MAX_NAME_LEN, "%s:%i is waiting\n", myHostName, myPID );
    }
    return 0;
}