int
rsDataObjLseek201 (rsComm_t *rsComm, fileLseekInp_t *dataObjLseekInp,
fileLseekOut_t **dataObjLseekOut)
{
    openedDataObjInp_t openedDataObjInp;
    int status;

    bzero (&openedDataObjInp, sizeof (openedDataObjInp));

    openedDataObjInp.l1descInx = dataObjLseekInp->fileInx;
    openedDataObjInp.offset = dataObjLseekInp->offset;
    openedDataObjInp.whence = dataObjLseekInp->whence;

    status = rsDataObjLseek (rsComm, &openedDataObjInp, dataObjLseekOut);

    return status;
}
Exemple #2
0
int _writeString( char *writeId, char *writeStr, ruleExecInfo_t *rei ) {

    // =-=-=-=-=-=-=-
    // JMC - backport 4619
    dataObjInp_t dataObjInp;
    openedDataObjInp_t openedDataObjInp;
    bytesBuf_t tmpBBuf;
    int fd, i;
    // =-=-=-=-=-=-=-

    if ( writeId != NULL && strcmp( writeId, "serverLog" ) == 0 ) {
        rodsLog( LOG_NOTICE, "writeString: inString = %s", writeStr );
        return 0;
    }

    // =-=-=-=-=-=-=-
    // JMC - backport 4619
    if ( writeId != NULL && writeId[0] == '/' ) {
        /* writing to an existing iRODS file */

        if ( rei == NULL || rei->rsComm == NULL ) {
            rodsLog( LOG_ERROR, "_writeString: input rei or rsComm is NULL" );
            return SYS_INTERNAL_NULL_INPUT_ERR;
        }

        bzero( &dataObjInp, sizeof( dataObjInp ) );
        dataObjInp.openFlags = O_RDWR;
        snprintf( dataObjInp.objPath, MAX_NAME_LEN, "%s", writeId );
        fd = rsDataObjOpen( rei->rsComm, &dataObjInp );
        if ( fd < 0 ) {
            rodsLog( LOG_ERROR, "_writeString: rsDataObjOpen failed. status = %d", fd );
            return fd;
        }

        bzero( &openedDataObjInp, sizeof( openedDataObjInp ) );
        openedDataObjInp.l1descInx = fd;
        openedDataObjInp.offset = 0;
        openedDataObjInp.whence = SEEK_END;
        fileLseekOut_t *dataObjLseekOut = NULL;
        i = rsDataObjLseek( rei->rsComm, &openedDataObjInp, &dataObjLseekOut );
        free( dataObjLseekOut );
        if ( i < 0 ) {
            rodsLog( LOG_ERROR, "_writeString: rsDataObjLseek failed. status = %d", i );
            return i;
        }

        bzero( &openedDataObjInp, sizeof( openedDataObjInp ) );
        openedDataObjInp.l1descInx = fd;
        tmpBBuf.len = openedDataObjInp.len = strlen( writeStr ) + 1;
        tmpBBuf.buf =  writeStr;
        i = rsDataObjWrite( rei->rsComm, &openedDataObjInp, &tmpBBuf );
        if ( i < 0 ) {
            rodsLog( LOG_ERROR, "_writeString: rsDataObjWrite failed. status = %d", i );
            return i;
        }

        bzero( &openedDataObjInp, sizeof( openedDataObjInp ) );
        openedDataObjInp.l1descInx = fd;
        i = rsDataObjClose( rei->rsComm, &openedDataObjInp );
        return i;
    }

    // =-=-=-=-=-=-=-

    msParam_t * mP = NULL;
    msParamArray_t * inMsParamArray = rei->msParamArray;
    execCmdOut_t *myExecCmdOut;
    if ( ( ( mP = getMsParamByLabel( inMsParamArray, "ruleExecOut" ) ) != NULL ) &&
            ( mP->inOutStruct != NULL ) ) {
        if ( !strcmp( mP->type, STR_MS_T ) ) {
            myExecCmdOut = ( execCmdOut_t* )malloc( sizeof( execCmdOut_t ) );
            memset( myExecCmdOut, 0, sizeof( execCmdOut_t ) );
            mP->inOutStruct = myExecCmdOut;
            mP->type = strdup( ExecCmdOut_MS_T );
        }
        else {
            myExecCmdOut = ( execCmdOut_t* )mP->inOutStruct;
        }
    }
    else {
        myExecCmdOut = ( execCmdOut_t* )malloc( sizeof( execCmdOut_t ) );
        memset( myExecCmdOut, 0, sizeof( execCmdOut_t ) );
        if ( mP == NULL ) {
            addMsParam( inMsParamArray, "ruleExecOut", ExecCmdOut_MS_T, myExecCmdOut, NULL );
        }
        else {
            mP->inOutStruct = myExecCmdOut;
            mP->type = strdup( ExecCmdOut_MS_T );
        }
    }

    /***** Jun 27, 2007
           i  = replaceVariablesAndMsParams("",writeStr, rei->msParamArray, rei);
           if (i < 0)
           return i;
    ****/

    if ( writeId != NULL ) {
        if ( !strcmp( writeId, "stdout" ) ) {
            appendToByteBuf( &( myExecCmdOut->stdoutBuf ), ( char * ) writeStr );
        }
        else if ( !strcmp( writeId, "stderr" ) ) {
            appendToByteBuf( &( myExecCmdOut->stderrBuf ), ( char * ) writeStr );
        }
    }

    return 0;
}