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/tools/omfwd.c
static rsRetVal doTryResume(wrkrInstanceData_t* pWrkrData)
{
    int iErr;
    struct addrinfo* res = NULL;
    struct addrinfo hints;
    instanceData* pData;
    int bBindRequired = 0;
    const char* address;
    DEFiRet;

    if (pWrkrData->bIsConnected)
        FINALIZE;
    pData = pWrkrData->pData;

    /* The remote address is not yet known and needs to be obtained */
    if (pData->protocol == FORW_UDP)
    {
        memset(&hints, 0, sizeof(hints));
        /* port must be numeric, because config file syntax requires this */
        hints.ai_flags = AI_NUMERICSERV;
        hints.ai_family = glbl.GetDefPFFamily();
        hints.ai_socktype = SOCK_DGRAM;
        if ((iErr = (getaddrinfo(pData->target, pData->port, &hints, &res))) !=
            0)
        {
            LogError(0, RS_RET_SUSPENDED,
                     "omfwd: could not get addrinfo for hostname '%s':'%s': %s",
                     pData->target, pData->port, gai_strerror(iErr));
            ABORT_FINALIZE(RS_RET_SUSPENDED);
        }
        address = pData->target;
        if (pData->address)
        {
            struct addrinfo* addr;
            /* The AF of the bind addr must match that of target */
            hints.ai_family = res->ai_family;
            hints.ai_flags |= AI_PASSIVE;
            iErr = getaddrinfo(pData->address, pData->port, &hints, &addr);
            freeaddrinfo(addr);
            if (iErr != 0)
            {
                LogError(
                    0, RS_RET_SUSPENDED,
                    "omfwd: cannot use bind address '%s' for host '%s': %s",
                    pData->address, pData->target, gai_strerror(iErr));
                ABORT_FINALIZE(RS_RET_SUSPENDED);
            }
            bBindRequired = 1;
            address = pData->address;
        }
        DBGPRINTF("%s found, resuming.\n", pData->target);
        pWrkrData->f_addr = res;
        res = NULL;
        if (pWrkrData->pSockArray == NULL)
        {
            CHKiRet(changeToNs(pData));
            pWrkrData->pSockArray = net.create_udp_socket(
                (uchar*)address, NULL, bBindRequired, 0, pData->UDPSendBuf,
                pData->ipfreebind, pData->device);
            CHKiRet(returnToOriginalNs(pData));
        }
        if (pWrkrData->pSockArray != NULL)
        {
            pWrkrData->bIsConnected = 1;
        }
    }
    else
    {
        CHKiRet(changeToNs(pData));
        CHKiRet(TCPSendInit((void*)pWrkrData));
        CHKiRet(returnToOriginalNs(pData));
    }

finalize_it:
    DBGPRINTF("omfwd: doTryResume %s iRet %d\n", pWrkrData->pData->target,
              iRet);
    if (res != NULL)
    {
        freeaddrinfo(res);
    }
    if (iRet != RS_RET_OK)
    {
        returnToOriginalNs(pData);
        if (pWrkrData->f_addr != NULL)
        {
            freeaddrinfo(pWrkrData->f_addr);
            pWrkrData->f_addr = NULL;
        }
        iRet = RS_RET_SUSPENDED;
    }

    RETiRet;
}
/* try to resume connection if it is not ready
 * rgerhards, 2007-08-02
 */
try to resume connection if it is not ready
rgerhards, 2007-08-02
try to resume connection if it is not ready rgerhards 2007 - 08 - 02
static rsRetVal doTryResume(wrkrInstanceData_t* pWrkrData)
{
    int iErr;
    struct addrinfo* res = NULL;
    struct addrinfo hints;
    instanceData* pData;
    int bBindRequired = 0;
    const char* address;
    DEFiRet;
    if (pWrkrData->bIsConnected)
        FINALIZE;
    pData = pWrkrData->pData;
    if (pData->protocol == FORW_UDP)
    {
        memset(&hints, 0, sizeof(hints));
        hints.ai_flags = AI_NUMERICSERV;
        hints.ai_family = glbl.GetDefPFFamily();
        hints.ai_socktype = SOCK_DGRAM;
        if ((iErr = (getaddrinfo(pData->target, pData->port, &hints, &res))) !=
            0)
        {
            LogError(0, RS_RET_SUSPENDED,
                     "omfwd: could not get addrinfo for hostname '%s':'%s': %s",
                     pData->target, pData->port, gai_strerror(iErr));
            ABORT_FINALIZE(RS_RET_SUSPENDED);
        }
        address = pData->target;
        if (pData->address)
        {
            struct addrinfo* addr;
            hints.ai_family = res->ai_family;
            hints.ai_flags |= AI_PASSIVE;
            iErr = getaddrinfo(pData->address, pData->port, &hints, &addr);
            freeaddrinfo(addr);
            if (iErr != 0)
            {
                LogError(
                    0, RS_RET_SUSPENDED,
                    "omfwd: cannot use bind address '%s' for host '%s': %s",
                    pData->address, pData->target, gai_strerror(iErr));
                ABORT_FINALIZE(RS_RET_SUSPENDED);
            }
            bBindRequired = 1;
            address = pData->address;
        }
        DBGPRINTF("%s found, resuming.\n", pData->target);
        pWrkrData->f_addr = res;
        res = NULL;
        if (pWrkrData->pSockArray == NULL)
        {
            CHKiRet(changeToNs(pData));
            pWrkrData->pSockArray = net.create_udp_socket(
                (uchar*)address, NULL, bBindRequired, 0, pData->UDPSendBuf,
                pData->ipfreebind, pData->device);
            CHKiRet(returnToOriginalNs(pData));
        }
        if (pWrkrData->pSockArray != NULL)
        {
            pWrkrData->bIsConnected = 1;
        }
    }
    else
    {
        CHKiRet(changeToNs(pData));
        CHKiRet(TCPSendInit((void*)pWrkrData));
        CHKiRet(returnToOriginalNs(pData));
    }
finalize_it:
    DBGPRINTF("omfwd: doTryResume %s iRet %d\n", pWrkrData->pData->target,
              iRet);
    if (res != NULL)
    {
        freeaddrinfo(res);
    }
    if (iRet != RS_RET_OK)
    {
        returnToOriginalNs(pData);
        if (pWrkrData->f_addr != NULL)
        {
            freeaddrinfo(pWrkrData->f_addr);
            pWrkrData->f_addr = NULL;
        }
        iRet = RS_RET_SUSPENDED;
    }
    RETiRet;
}
static rsRetVal doTryResume ( wrkrInstanceData_t * pWrkrData ) { int iErr ; struct addrinfo * res = NULL ; struct addrinfo hints ; instanceData * pData ; int bBindRequired = 0 ; const char * address ; DEFiRet ; if ( pWrkrData -> bIsConnected ) FINALIZE ; pData = pWrkrData -> pData ; if ( pData -> protocol == FORW_UDP ) { memset ( & hints , 0 , sizeof ( hints ) ) ; hints . ai_flags = AI_NUMERICSERV ; hints . ai_family = glbl . GetDefPFFamily ( ) ; hints . ai_socktype = SOCK_DGRAM ; if ( ( iErr = ( getaddrinfo ( pData -> target , pData -> port , & hints , & res ) ) ) != 0 ) { LogError ( 0 , RS_RET_SUSPENDED , " " , pData -> target , pData -> port , gai_strerror ( iErr ) ) ; ABORT_FINALIZE ( RS_RET_SUSPENDED ) ; } address = pData -> target ; if ( pData -> address ) { struct addrinfo * addr ; hints . ai_family = res -> ai_family ; hints . ai_flags |= AI_PASSIVE ; iErr = getaddrinfo ( pData -> address , pData -> port , & hints , & addr ) ; freeaddrinfo ( addr ) ; if ( iErr != 0 ) { LogError ( 0 , RS_RET_SUSPENDED , " " , pData -> address , pData -> target , gai_strerror ( iErr ) ) ; ABORT_FINALIZE ( RS_RET_SUSPENDED ) ; } bBindRequired = 1 ; address = pData -> address ; } DBGPRINTF ( " \n " , pData -> target ) ; pWrkrData -> f_addr = res ; res = NULL ; if ( pWrkrData -> pSockArray == NULL ) { CHKiRet ( changeToNs ( pData ) ) ; pWrkrData -> pSockArray = net . create_udp_socket ( ( uchar * ) address , NULL , bBindRequired , 0 , pData -> UDPSendBuf , pData -> ipfreebind , pData -> device ) ; CHKiRet ( returnToOriginalNs ( pData ) ) ; } if ( pWrkrData -> pSockArray != NULL ) { pWrkrData -> bIsConnected = 1 ; } } else { CHKiRet ( changeToNs ( pData ) ) ; CHKiRet ( TCPSendInit ( ( void * ) pWrkrData ) ) ; CHKiRet ( returnToOriginalNs ( pData ) ) ; } finalize_it : DBGPRINTF ( " \n " , pWrkrData -> pData -> target , iRet ) ; if ( res != NULL ) { freeaddrinfo ( res ) ; } if ( iRet != RS_RET_OK ) { returnToOriginalNs ( pData ) ; if ( pWrkrData -> f_addr != NULL ) { freeaddrinfo ( pWrkrData -> f_addr ) ; pWrkrData -> f_addr = NULL ; } iRet = RS_RET_SUSPENDED ; } RETiRet ; }
try to resume connection if it is not ready
 rgerhards, 2007-08-02
try to resume connection if it is not ready rgerhards 2007 - 08 - 02
/* The remote address is not yet known and needs to be obtained */ /* port must be numeric, because config file syntax requires this */ /* The AF of the bind addr must match that of target */