openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rsyslog/8.1903.0-r0/rsyslog-8.1903.0/runtime/stream.c
static rsRetVal doPhysOpen(strm_t* pThis)
{
    int iFlags = 0;
    struct stat statOpen;
    DEFiRet;
    ISOBJ_TYPE_assert(pThis, strm);

    /* compute which flags we need to provide to open */
    switch (pThis->tOperationsMode)
    {
        case STREAMMODE_READ:
            iFlags = O_CLOEXEC | O_NOCTTY | O_RDONLY;
            break;
        case STREAMMODE_WRITE: /* legacy mode used inside queue engine */
            iFlags = O_CLOEXEC | O_NOCTTY | O_WRONLY | O_CREAT;
            break;
        case STREAMMODE_WRITE_TRUNC:
            iFlags = O_CLOEXEC | O_NOCTTY | O_WRONLY | O_CREAT | O_TRUNC;
            break;
        case STREAMMODE_WRITE_APPEND:
            iFlags = O_CLOEXEC | O_NOCTTY | O_WRONLY | O_CREAT | O_APPEND;
            break;
        case STREAMMMODE_INVALID:
        default:
            assert(0);
            break;
    }
    if (pThis->sType == STREAMTYPE_NAMED_PIPE)
    {
        DBGPRINTF("Note: stream '%s' is a named pipe, open with O_NONBLOCK\n",
                  pThis->pszCurrFName);
        iFlags |= O_NONBLOCK;
    }

    pThis->fd = open((char*)pThis->pszCurrFName, iFlags | O_LARGEFILE,
                     pThis->tOpenMode);
    const int errno_save = errno; /* dbgprintf can mangle it! */
    DBGPRINTF("file '%s' opened as #%d with mode %d\n", pThis->pszCurrFName,
              pThis->fd, (int)pThis->tOpenMode);
    if (pThis->fd == -1)
    {
        const rsRetVal errcode = (errno_save == ENOENT)
                                     ? RS_RET_FILE_NOT_FOUND
                                     : RS_RET_FILE_OPEN_ERROR;
        if (pThis->fileNotFoundError)
        {
            if (pThis->noRepeatedErrorOutput == 0)
            {
                LogError(errno_save, errcode, "file '%s': open error",
                         pThis->pszCurrFName);
                pThis->noRepeatedErrorOutput = 1;
            }
        }
        else
        {
            DBGPRINTF("file '%s': open error", pThis->pszCurrFName);
        }
        ABORT_FINALIZE(errcode);
    }
    else
    {
        pThis->noRepeatedErrorOutput = 0;
    }

    if (pThis->tOperationsMode == STREAMMODE_READ)
    {
        if (fstat(pThis->fd, &statOpen) == -1)
        {
            DBGPRINTF("Error: cannot obtain inode# for file %s\n",
                      pThis->pszCurrFName);
            ABORT_FINALIZE(RS_RET_IO_ERROR);
        }
        pThis->inode = statOpen.st_ino;
    }

    if (!ustrcmp(pThis->pszCurrFName, UCHAR_CONSTANT(_PATH_CONSOLE)) ||
        isatty(pThis->fd))
    {
        DBGPRINTF("file %d is a tty-type file\n", pThis->fd);
        pThis->bIsTTY = 1;
    }
    else
    {
        pThis->bIsTTY = 0;
    }

    if (pThis->cryprov != NULL)
    {
        CHKiRet(pThis->cryprov->OnFileOpen(
            pThis->cryprovData, pThis->pszCurrFName, &pThis->cryprovFileData,
            (pThis->tOperationsMode == STREAMMODE_READ) ? 'r' : 'w'));
        pThis->cryprov->SetDeleteOnClose(pThis->cryprovFileData,
                                         pThis->bDeleteOnClose);
    }

finalize_it:
    RETiRet;
}
/* do the physical open() call on a file.
 */
do the physical open() call on a file.
do the physical open () call on a file .
static rsRetVal doPhysOpen(strm_t* pThis)
{
    int iFlags = 0;
    struct stat statOpen;
    DEFiRet;
    ISOBJ_TYPE_assert(pThis, strm);
    switch (pThis->tOperationsMode)
    {
        case STREAMMODE_READ:
            iFlags = O_CLOEXEC | O_NOCTTY | O_RDONLY;
            break;
        case STREAMMODE_WRITE: 
            iFlags = O_CLOEXEC | O_NOCTTY | O_WRONLY | O_CREAT;
            break;
        case STREAMMODE_WRITE_TRUNC:
            iFlags = O_CLOEXEC | O_NOCTTY | O_WRONLY | O_CREAT | O_TRUNC;
            break;
        case STREAMMODE_WRITE_APPEND:
            iFlags = O_CLOEXEC | O_NOCTTY | O_WRONLY | O_CREAT | O_APPEND;
            break;
        case STREAMMMODE_INVALID:
        default:
            assert(0);
            break;
    }
    if (pThis->sType == STREAMTYPE_NAMED_PIPE)
    {
        DBGPRINTF("Note: stream '%s' is a named pipe, open with O_NONBLOCK\n",
                  pThis->pszCurrFName);
        iFlags |= O_NONBLOCK;
    }
    pThis->fd = open((char*)pThis->pszCurrFName, iFlags | O_LARGEFILE,
                     pThis->tOpenMode);
    const int errno_save = errno; 
    DBGPRINTF("file '%s' opened as #%d with mode %d\n", pThis->pszCurrFName,
              pThis->fd, (int)pThis->tOpenMode);
    if (pThis->fd == -1)
    {
        const rsRetVal errcode = (errno_save == ENOENT)
                                     ? RS_RET_FILE_NOT_FOUND
                                     : RS_RET_FILE_OPEN_ERROR;
        if (pThis->fileNotFoundError)
        {
            if (pThis->noRepeatedErrorOutput == 0)
            {
                LogError(errno_save, errcode, "file '%s': open error",
                         pThis->pszCurrFName);
                pThis->noRepeatedErrorOutput = 1;
            }
        }
        else
        {
            DBGPRINTF("file '%s': open error", pThis->pszCurrFName);
        }
        ABORT_FINALIZE(errcode);
    }
    else
    {
        pThis->noRepeatedErrorOutput = 0;
    }
    if (pThis->tOperationsMode == STREAMMODE_READ)
    {
        if (fstat(pThis->fd, &statOpen) == -1)
        {
            DBGPRINTF("Error: cannot obtain inode# for file %s\n",
                      pThis->pszCurrFName);
            ABORT_FINALIZE(RS_RET_IO_ERROR);
        }
        pThis->inode = statOpen.st_ino;
    }
    if (!ustrcmp(pThis->pszCurrFName, UCHAR_CONSTANT(_PATH_CONSOLE)) ||
        isatty(pThis->fd))
    {
        DBGPRINTF("file %d is a tty-type file\n", pThis->fd);
        pThis->bIsTTY = 1;
    }
    else
    {
        pThis->bIsTTY = 0;
    }
    if (pThis->cryprov != NULL)
    {
        CHKiRet(pThis->cryprov->OnFileOpen(
            pThis->cryprovData, pThis->pszCurrFName, &pThis->cryprovFileData,
            (pThis->tOperationsMode == STREAMMODE_READ) ? 'r' : 'w'));
        pThis->cryprov->SetDeleteOnClose(pThis->cryprovFileData,
                                         pThis->bDeleteOnClose);
    }
finalize_it:
    RETiRet;
}
static rsRetVal doPhysOpen ( strm_t * pThis ) { int iFlags = 0 ; struct stat statOpen ; DEFiRet ; ISOBJ_TYPE_assert ( pThis , strm ) ; switch ( pThis -> tOperationsMode ) { case STREAMMODE_READ : iFlags = O_CLOEXEC | O_NOCTTY | O_RDONLY ; break ; case STREAMMODE_WRITE : iFlags = O_CLOEXEC | O_NOCTTY | O_WRONLY | O_CREAT ; break ; case STREAMMODE_WRITE_TRUNC : iFlags = O_CLOEXEC | O_NOCTTY | O_WRONLY | O_CREAT | O_TRUNC ; break ; case STREAMMODE_WRITE_APPEND : iFlags = O_CLOEXEC | O_NOCTTY | O_WRONLY | O_CREAT | O_APPEND ; break ; case STREAMMMODE_INVALID : default : assert ( 0 ) ; break ; } if ( pThis -> sType == STREAMTYPE_NAMED_PIPE ) { DBGPRINTF ( " \n " , pThis -> pszCurrFName ) ; iFlags |= O_NONBLOCK ; } pThis -> fd = open ( ( char * ) pThis -> pszCurrFName , iFlags | O_LARGEFILE , pThis -> tOpenMode ) ; const int errno_save = errno ; DBGPRINTF ( " \n " , pThis -> pszCurrFName , pThis -> fd , ( int ) pThis -> tOpenMode ) ; if ( pThis -> fd == -1 ) { const rsRetVal errcode = ( errno_save == ENOENT ) ? RS_RET_FILE_NOT_FOUND : RS_RET_FILE_OPEN_ERROR ; if ( pThis -> fileNotFoundError ) { if ( pThis -> noRepeatedErrorOutput == 0 ) { LogError ( errno_save , errcode , " " , pThis -> pszCurrFName ) ; pThis -> noRepeatedErrorOutput = 1 ; } } else { DBGPRINTF ( " " , pThis -> pszCurrFName ) ; } ABORT_FINALIZE ( errcode ) ; } else { pThis -> noRepeatedErrorOutput = 0 ; } if ( pThis -> tOperationsMode == STREAMMODE_READ ) { if ( fstat ( pThis -> fd , & statOpen ) == -1 ) { DBGPRINTF ( " \n " , pThis -> pszCurrFName ) ; ABORT_FINALIZE ( RS_RET_IO_ERROR ) ; } pThis -> inode = statOpen . st_ino ; } if ( ! ustrcmp ( pThis -> pszCurrFName , UCHAR_CONSTANT ( _PATH_CONSOLE ) ) || isatty ( pThis -> fd ) ) { DBGPRINTF ( " \n " , pThis -> fd ) ; pThis -> bIsTTY = 1 ; } else { pThis -> bIsTTY = 0 ; } if ( pThis -> cryprov != NULL ) { CHKiRet ( pThis -> cryprov -> OnFileOpen ( pThis -> cryprovData , pThis -> pszCurrFName , & pThis -> cryprovFileData , ( pThis -> tOperationsMode == STREAMMODE_READ ) ? ' ' : ' ' ) ) ; pThis -> cryprov -> SetDeleteOnClose ( pThis -> cryprovFileData , pThis -> bDeleteOnClose ) ; } finalize_it : RETiRet ; }
do the physical open() call on a file.
do the physical open () call on a file .
/* compute which flags we need to provide to open */ /* legacy mode used inside queue engine */ /* dbgprintf can mangle it! */