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/nsd_ptcp.c
static rsRetVal AcceptConnReq(nsd_t* pNsd, nsd_t** ppNew)
{
    int sockflags;
    nsd_ptcp_t* pThis = (nsd_ptcp_t*)pNsd;
    struct sockaddr_storage addr;
    socklen_t addrlen = sizeof(addr);
    nsd_ptcp_t* pNew = NULL;
    int iNewSock = -1;

    DEFiRet;
    assert(ppNew != NULL);
    ISOBJ_TYPE_assert(pThis, nsd_ptcp);

    iNewSock = accept(pThis->sock, (struct sockaddr*)&addr, &addrlen);
    if (iNewSock < 0)
    {
        if (Debug)
        {
            char errStr[1024];
            rs_strerror_r(errno, errStr, sizeof(errStr));
            dbgprintf("nds_ptcp: error accepting connection on socket %d, "
                      "errno %d: %s\n",
                      pThis->sock, errno, errStr);
        }
        ABORT_FINALIZE(RS_RET_ACCEPT_ERR);
    }

    /* construct our object so that we can use it... */
    CHKiRet(nsd_ptcpConstruct(&pNew));

    /* for the legacy ACL code, we need to preserve addr. While this is far from
     * begin perfect (from an abstract design perspective), we need this to
     * prevent breaking everything. TODO: we need to implement a new ACL module
     * to get rid of this function. -- rgerhards, 2008-12-01
     */
    memcpy(&pNew->remAddr, &addr, sizeof(struct sockaddr_storage));
    CHKiRet(FillRemHost(pNew, &addr));

    /* set the new socket to non-blocking IO -TODO:do we really need to do this
     * here? Do we always want it? */
    if ((sockflags = fcntl(iNewSock, F_GETFL)) != -1)
    {
        sockflags |= O_NONBLOCK;
        /* SETFL could fail too, so get it caught by the subsequent
         * error check.
         */
        sockflags = fcntl(iNewSock, F_SETFL, sockflags);
    }
    if (sockflags == -1)
    {
        dbgprintf("error %d setting fcntl(O_NONBLOCK) on tcp socket %d", errno,
                  iNewSock);
        ABORT_FINALIZE(RS_RET_IO_ERROR);
    }

    pNew->sock = iNewSock;
    *ppNew = (nsd_t*)pNew;

finalize_it:
    if (iRet != RS_RET_OK)
    {
        if (pNew != NULL)
            nsd_ptcpDestruct(&pNew);
        /* the close may be redundant, but that doesn't hurt... */
        sockClose(&iNewSock);
    }

    RETiRet;
}
/* accept an incoming connection request
 * rgerhards, 2008-04-22
 */
accept an incoming connection request
rgerhards, 2008-04-22
accept an incoming connection request rgerhards 2008 - 04 - 22
static rsRetVal AcceptConnReq(nsd_t* pNsd, nsd_t** ppNew)
{
    int sockflags;
    nsd_ptcp_t* pThis = (nsd_ptcp_t*)pNsd;
    struct sockaddr_storage addr;
    socklen_t addrlen = sizeof(addr);
    nsd_ptcp_t* pNew = NULL;
    int iNewSock = -1;
    DEFiRet;
    assert(ppNew != NULL);
    ISOBJ_TYPE_assert(pThis, nsd_ptcp);
    iNewSock = accept(pThis->sock, (struct sockaddr*)&addr, &addrlen);
    if (iNewSock < 0)
    {
        if (Debug)
        {
            char errStr[1024];
            rs_strerror_r(errno, errStr, sizeof(errStr));
            dbgprintf("nds_ptcp: error accepting connection on socket %d, "
                      "errno %d: %s\n",
                      pThis->sock, errno, errStr);
        }
        ABORT_FINALIZE(RS_RET_ACCEPT_ERR);
    }
    CHKiRet(nsd_ptcpConstruct(&pNew));
    memcpy(&pNew->remAddr, &addr, sizeof(struct sockaddr_storage));
    CHKiRet(FillRemHost(pNew, &addr));
    if ((sockflags = fcntl(iNewSock, F_GETFL)) != -1)
    {
        sockflags |= O_NONBLOCK;
        sockflags = fcntl(iNewSock, F_SETFL, sockflags);
    }
    if (sockflags == -1)
    {
        dbgprintf("error %d setting fcntl(O_NONBLOCK) on tcp socket %d", errno,
                  iNewSock);
        ABORT_FINALIZE(RS_RET_IO_ERROR);
    }
    pNew->sock = iNewSock;
    *ppNew = (nsd_t*)pNew;
finalize_it:
    if (iRet != RS_RET_OK)
    {
        if (pNew != NULL)
            nsd_ptcpDestruct(&pNew);
        sockClose(&iNewSock);
    }
    RETiRet;
}
static rsRetVal AcceptConnReq ( nsd_t * pNsd , nsd_t * * ppNew ) { int sockflags ; nsd_ptcp_t * pThis = ( nsd_ptcp_t * ) pNsd ; struct sockaddr_storage addr ; socklen_t addrlen = sizeof ( addr ) ; nsd_ptcp_t * pNew = NULL ; int iNewSock = -1 ; DEFiRet ; assert ( ppNew != NULL ) ; ISOBJ_TYPE_assert ( pThis , nsd_ptcp ) ; iNewSock = accept ( pThis -> sock , ( struct sockaddr * ) & addr , & addrlen ) ; if ( iNewSock < 0 ) { if ( Debug ) { char errStr [ 1024 ] ; rs_strerror_r ( errno , errStr , sizeof ( errStr ) ) ; dbgprintf ( " " " \n " , pThis -> sock , errno , errStr ) ; } ABORT_FINALIZE ( RS_RET_ACCEPT_ERR ) ; } CHKiRet ( nsd_ptcpConstruct ( & pNew ) ) ; memcpy ( & pNew -> remAddr , & addr , sizeof ( struct sockaddr_storage ) ) ; CHKiRet ( FillRemHost ( pNew , & addr ) ) ; if ( ( sockflags = fcntl ( iNewSock , F_GETFL ) ) != -1 ) { sockflags |= O_NONBLOCK ; sockflags = fcntl ( iNewSock , F_SETFL , sockflags ) ; } if ( sockflags == -1 ) { dbgprintf ( " " , errno , iNewSock ) ; ABORT_FINALIZE ( RS_RET_IO_ERROR ) ; } pNew -> sock = iNewSock ; * ppNew = ( nsd_t * ) pNew ; finalize_it : if ( iRet != RS_RET_OK ) { if ( pNew != NULL ) nsd_ptcpDestruct ( & pNew ) ; sockClose ( & iNewSock ) ; } RETiRet ; }
accept an incoming connection request
 rgerhards, 2008-04-22
accept an incoming connection request rgerhards 2008 - 04 - 22
/* construct our object so that we can use it... */ /* for the legacy ACL code, we need to preserve addr. While this is far from
     * begin perfect (from an abstract design perspective), we need this to
     * prevent breaking everything. TODO: we need to implement a new ACL module
     * to get rid of this function. -- rgerhards, 2008-12-01
     */ /* set the new socket to non-blocking IO -TODO:do we really need to do this
     * here? Do we always want it? */ /* SETFL could fail too, so get it caught by the subsequent
         * error check.
         */ /* the close may be redundant, but that doesn't hurt... */