diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2009-11-25 13:28:05 +0100 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2009-11-25 13:28:05 +0100 |
commit | 18749309f333ee83d5fc14d64971e0418eef360d (patch) | |
tree | 9f237e80f4e70bb5d4ad2dd528a010d43960ce45 /runtime | |
parent | e0d77fa90cad334f308da9cbd4369d61f1c97511 (diff) | |
download | rsyslog-18749309f333ee83d5fc14d64971e0418eef360d.tar.gz rsyslog-18749309f333ee83d5fc14d64971e0418eef360d.tar.xz rsyslog-18749309f333ee83d5fc14d64971e0418eef360d.zip |
fixing some potential segfault conditions
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/nsd_ptcp.c | 5 | ||||
-rw-r--r-- | runtime/nsdpoll_ptcp.c | 15 | ||||
-rw-r--r-- | runtime/rsyslog.h | 1 |
3 files changed, 15 insertions, 6 deletions
diff --git a/runtime/nsd_ptcp.c b/runtime/nsd_ptcp.c index 6feee71d..96881097 100644 --- a/runtime/nsd_ptcp.c +++ b/runtime/nsd_ptcp.c @@ -562,6 +562,7 @@ finalize_it: static rsRetVal Rcv(nsd_t *pNsd, uchar *pRcvBuf, ssize_t *pLenBuf) { + char errStr[1024]; DEFiRet; nsd_ptcp_t *pThis = (nsd_ptcp_t*) pNsd; ISOBJ_TYPE_assert(pThis, nsd_ptcp); @@ -571,7 +572,9 @@ Rcv(nsd_t *pNsd, uchar *pRcvBuf, ssize_t *pLenBuf) if(*pLenBuf == 0) { ABORT_FINALIZE(RS_RET_CLOSED); } else if (*pLenBuf < 0) { - ABORT_FINALIZE(RS_RET_ERR); + rs_strerror_r(errno, errStr, sizeof(errStr)); + dbgprintf("error during recv on NSD %p: %s\n", pNsd, errStr); + ABORT_FINALIZE(RS_RET_RCV_ERR); } finalize_it: diff --git a/runtime/nsdpoll_ptcp.c b/runtime/nsdpoll_ptcp.c index 95fd8aa3..445ecc71 100644 --- a/runtime/nsdpoll_ptcp.c +++ b/runtime/nsdpoll_ptcp.c @@ -52,6 +52,12 @@ DEFobjCurrIf(glbl) /* add new entry to list. We assume that the fd is not already present and DO NOT check this! * Returns newly created entry in pEvtLst. + * Note that we currently need to use level-triggered mode, because the upper layers do not work + * in parallel. As such, in edge-triggered mode we may not get notified, because new data comes + * in after we have read everything that was present. To use ET mode, we need to change the upper + * peers so that they immediately start a new wait before processing the data read. That obviously + * requires more elaborate redesign and we postpone this until the current more simplictic mode has + * been proven OK in practice. * rgerhards, 2009-11-18 */ static inline rsRetVal @@ -63,7 +69,7 @@ addEvent(nsdpoll_ptcp_t *pThis, int id, void *pUsr, int mode, nsd_ptcp_t *pSock, pNew->id = id; pNew->pUsr = pUsr; pNew->pSock = pSock; - pNew->event.events = EPOLLET; /* always use edge-triggered mode */ + pNew->event.events = 0; /* TODO: at some time we should be able to use EPOLLET */ if(mode & NSDPOLL_IN) pNew->event.events |= EPOLLIN; if(mode & NSDPOLL_OUT) @@ -88,7 +94,7 @@ unlinkEvent(nsdpoll_ptcp_t *pThis, int id, void *pUsr, nsdpoll_epollevt_lst_t ** DEFiRet; pEvtLst = pThis->pRoot; - while(pEvtLst != NULL && pEvtLst->id != id && pEvtLst->pUsr != pUsr) { + while(pEvtLst != NULL && !(pEvtLst->id == id && pEvtLst->pUsr == pUsr)) { pPrev = pEvtLst; pEvtLst = pEvtLst->pNext; } @@ -158,7 +164,7 @@ Ctl(nsdpoll_t *pNsdpoll, nsd_t *pNsd, int id, void *pUsr, int mode, int op) { DEFiRet; if(op == NSDPOLL_ADD) { - dbgprintf("adding nsdpoll entry %d/%p\n", id, pUsr); + dbgprintf("adding nsdpoll entry %d/%p, sock %d\n", id, pUsr, pSock->sock); CHKiRet(addEvent(pThis, id, pUsr, mode, pSock, &pEventLst)); if(epoll_ctl(pThis->efd, EPOLL_CTL_ADD, pSock->sock, &pEventLst->event) < 0) { errSave = errno; @@ -168,8 +174,7 @@ Ctl(nsdpoll_t *pNsdpoll, nsd_t *pNsd, int id, void *pUsr, int mode, int op) { pSock->sock, id, pUsr, mode, errStr); } } else if(op == NSDPOLL_DEL) { - // TODO: XXX : code missing! del Event - dbgprintf("removing nsdpoll entry %d/%p\n", id, pUsr); + dbgprintf("removing nsdpoll entry %d/%p, sock %d\n", id, pUsr, pSock->sock); CHKiRet(unlinkEvent(pThis, id, pUsr, &pEventLst)); if(epoll_ctl(pThis->efd, EPOLL_CTL_DEL, pSock->sock, &pEventLst->event) < 0) { errSave = errno; diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index b8ebafd9..1431c684 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -418,6 +418,7 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth RS_RET_ERR_EPOLL = -2162, /**< epoll() returned with an unexpected error code */ RS_RET_ERR_EPOLL_CTL = -2163, /**< epol_ctll() returned with an unexpected error code */ RS_RET_TIMEOUT = -2164, /**< timeout occured during operation */ + RS_RET_RCV_ERR = -2165, /**< error occured during socket rcv operation */ /* RainerScript error messages (range 1000.. 1999) */ RS_RET_SYSVAR_NOT_FOUND = 1001, /**< system variable could not be found (maybe misspelled) */ |