diff options
-rw-r--r-- | module-template.h | 30 | ||||
-rw-r--r-- | modules.c | 4 | ||||
-rw-r--r-- | modules.h | 1 | ||||
-rw-r--r-- | omdiscard.c | 8 | ||||
-rw-r--r-- | omfile.c | 8 | ||||
-rw-r--r-- | omfwd.c | 22 | ||||
-rw-r--r-- | ommysql.c | 8 | ||||
-rw-r--r-- | omshell.c | 8 | ||||
-rw-r--r-- | omusrmsg.c | 8 | ||||
-rw-r--r-- | syslogd.c | 24 |
10 files changed, 102 insertions, 19 deletions
diff --git a/module-template.h b/module-template.h index 3a8b9129..200a48c0 100644 --- a/module-template.h +++ b/module-template.h @@ -76,7 +76,7 @@ static rsRetVal freeInstance(selector_t *f, void* pModData)\ /* isCompatibleWithFeature() */ #define BEGINisCompatibleWithFeature \ -static rsRetVal isCompatibleWithFeature(syslogFeature eFeat)\ +static rsRetVal isCompatibleWithFeature(syslogFeature __attribute__((unused)) eFeat)\ {\ rsRetVal iRet = RS_RET_INCOMPATIBLE; @@ -120,10 +120,34 @@ static rsRetVal dbgPrintInstInfo(selector_t *f, void *pModData)\ } +/* onSelectReadyWrite() + * Extra comments: + * This is called when select() returned with a writable file descriptor + * for this module. The fd was most probably obtained by getWriteFDForSelect() + * before. + */ +#define BEGINonSelectReadyWrite \ +static rsRetVal onSelectReadyWrite(selector_t *f, void *pModData)\ +{\ + rsRetVal iRet = RS_RET_NONE;\ + instanceData *pData = NULL; + +#define CODESTARTonSelectReadyWrite \ + assert(f != NULL);\ + pData = (instanceData*) pModData; + +#define ENDonSelectReadyWrite \ + return iRet;\ +} + /* getWriteFDForSelect() * Extra comments: - * Print debug information about this instance. + * Gets writefd for select call. Must only be returned when the selector must + * be written to. If the module has no such fds, it must return RS_RET_NONE. + * In this case, the default implementation is sufficient. + * This interface will probably go away over time, but we need it now to + * continue modularization. */ #define BEGINgetWriteFDForSelect \ static rsRetVal getWriteFDForSelect(selector_t *f, void *pModData, short *fd)\ @@ -198,6 +222,8 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())\ *pEtryPoint = freeInstance;\ } else if(!strcmp((char*) name, "getWriteFDForSelect")) {\ *pEtryPoint = getWriteFDForSelect;\ + } else if(!strcmp((char*) name, "onSelectReadyWrite")) {\ + *pEtryPoint = onSelectReadyWrite;\ } /* modInit() @@ -184,6 +184,10 @@ rsRetVal doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)()), uchar *name) moduleDestruct(pNew); return iRet; } + if((iRet = (*pNew->modQueryEtryPt)((uchar*)"onSelectReadyWrite", &pNew->onSelectReadyWrite)) != RS_RET_OK) { + moduleDestruct(pNew); + return iRet; + } if((iRet = (*pNew->modQueryEtryPt)((uchar*)"freeInstance", &pNew->freeInstance)) != RS_RET_OK) { moduleDestruct(pNew); return iRet; @@ -56,6 +56,7 @@ typedef struct moduleInfo { rsRetVal (*isCompatibleWithFeature)(syslogFeature); rsRetVal (*freeInstance)(struct filed*, void*);/* called before termination or module unload */ rsRetVal (*getWriteFDForSelect)(struct filed*, void*,short *);/* called before termination or module unload */ + rsRetVal (*onSelectReadyWrite)(struct filed*, void*);/* called when fd is writeable after select() */ rsRetVal (*dbgPrintInstInfo)(struct filed*, void*);/* called before termination or module unload */ rsRetVal (*modExit)(); /* called before termination or module unload */ /* below: parse a configuration line - return if processed diff --git a/omdiscard.c b/omdiscard.c index 03608bd7..0dbdc6d5 100644 --- a/omdiscard.c +++ b/omdiscard.c @@ -1,6 +1,9 @@ /* omdiscard.c * This is the implementation of the built-in discard output module. * + * NOTE: read comments in module-template.h to understand how this file + * works! + * * File begun on 2007-07-24 by RGerhards * * Copyright 2007 Rainer Gerhards and Adiscon GmbH. @@ -92,6 +95,11 @@ CODESTARTparseSelectorAct ENDparseSelectorAct +BEGINonSelectReadyWrite +CODESTARTonSelectReadyWrite +ENDonSelectReadyWrite + + BEGINgetWriteFDForSelect CODESTARTgetWriteFDForSelect ENDgetWriteFDForSelect @@ -3,6 +3,9 @@ * * Handles: F_CONSOLE, F_TTY, F_FILE, F_PIPE * + * NOTE: read comments in module-template.h to understand how this file + * works! + * * File begun on 2007-07-21 by RGerhards (extracted from syslogd.c) * This file is under development and has not yet arrived at being fully * self-contained and a real object. So far, it is mostly an excerpt @@ -542,6 +545,11 @@ CODESTARTfreeInstance ENDfreeInstance +BEGINonSelectReadyWrite +CODESTARTonSelectReadyWrite +ENDonSelectReadyWrite + + BEGINgetWriteFDForSelect CODESTARTgetWriteFDForSelect ENDgetWriteFDForSelect @@ -1,6 +1,9 @@ /* omfwd.c * This is the implementation of the build-in forwarding output module. * + * NOTE: read comments in module-template.h to understand how this file + * works! + * * File begun on 2007-07-20 by RGerhards (extracted from syslogd.c) * This file is under development and has not yet arrived at being fully * self-contained and a real object. So far, it is mostly an excerpt @@ -475,6 +478,25 @@ CODESTARTparseSelectorAct ENDparseSelectorAct +BEGINonSelectReadyWrite +CODESTARTonSelectReadyWrite + dprintf("tcp send socket %d ready for writing.\n", f->f_file); + TCPSendSetStatus(f, TCP_SEND_READY); + /* Send stored message (if any) */ + if(f->f_un.f_forw.savedMsg != NULL) { + if(TCPSend(f, f->f_un.f_forw.savedMsg, + f->f_un.f_forw.savedMsgLen) != 0) { + /* error! */ + f->f_type = F_FORW_SUSP; + errno = 0; + logerror("error forwarding via tcp, suspending..."); + } + free(f->f_un.f_forw.savedMsg); + f->f_un.f_forw.savedMsg = NULL; + } +ENDonSelectReadyWrite + + BEGINgetWriteFDForSelect CODESTARTgetWriteFDForSelect if( (f->f_type == F_FORW) @@ -1,6 +1,9 @@ /* omusrmsg.c * This is the implementation of the build-in output module for MySQL. * + * NOTE: read comments in module-template.h to understand how this file + * works! + * * File begun on 2007-07-20 by RGerhards (extracted from syslogd.c) * This file is under development and has not yet arrived at being fully * self-contained and a real object. So far, it is mostly an excerpt @@ -79,6 +82,11 @@ CODESTARTdbgPrintInstInfo ENDdbgPrintInstInfo +BEGINonSelectReadyWrite +CODESTARTonSelectReadyWrite +ENDonSelectReadyWrite + + BEGINgetWriteFDForSelect CODESTARTgetWriteFDForSelect ENDgetWriteFDForSelect @@ -1,6 +1,9 @@ /* omshell.c * This is the implementation of the build-in shell output module. * + * NOTE: read comments in module-template.h to understand how this file + * works! + * * shell support was initially written by bkalkbrenner 2005-09-20 * * File begun on 2007-07-20 by RGerhards (extracted from syslogd.c) @@ -120,6 +123,11 @@ CODESTARTparseSelectorAct ENDparseSelectorAct +BEGINonSelectReadyWrite +CODESTARTonSelectReadyWrite +ENDonSelectReadyWrite + + BEGINgetWriteFDForSelect CODESTARTgetWriteFDForSelect ENDgetWriteFDForSelect @@ -2,6 +2,9 @@ * This is the implementation of the build-in output module for sending * user messages. * + * NOTE: read comments in module-template.h to understand how this file + * works! + * * File begun on 2007-07-20 by RGerhards (extracted from syslogd.c) * This file is under development and has not yet arrived at being fully * self-contained and a real object. So far, it is mostly an excerpt @@ -319,6 +322,11 @@ CODESTARTparseSelectorAct ENDparseSelectorAct +BEGINonSelectReadyWrite +CODESTARTonSelectReadyWrite +ENDonSelectReadyWrite + + BEGINgetWriteFDForSelect CODESTARTgetWriteFDForSelect ENDgetWriteFDForSelect @@ -4032,7 +4032,6 @@ static void freeSelectors(void) selector_t *f; selector_t *fPrev; - Initialized = 0; if(Files != NULL) { dprintf("Freeing log structures.\n"); @@ -4073,6 +4072,7 @@ static void freeSelectors(void) /* Reflect the deletion of the selectors linked list. */ Files = NULL; + Initialized = 0; } } @@ -5372,24 +5372,14 @@ static void mainloop(void) * this code here will stay for quite a while. * rgerhards, 2006-12-07 */ + short fdMod; + rsRetVal iRet; for (f = Files; f != NULL ; f = f->f_next) { - if( (f->f_type == F_FORW) - && (f->f_un.f_forw.protocol == FORW_TCP) - && (TCPSendGetStatus(f) == TCP_SEND_CONNECTING) - && (FD_ISSET(f->f_file, &writefds))) { - dprintf("tcp send socket %d ready for writing.\n", f->f_file); - TCPSendSetStatus(f, TCP_SEND_READY); - /* Send stored message (if any) */ - if(f->f_un.f_forw.savedMsg != NULL) { - if(TCPSend(f, f->f_un.f_forw.savedMsg, - f->f_un.f_forw.savedMsgLen) != 0) { - /* error! */ - f->f_type = F_FORW_SUSP; - errno = 0; - logerror("error forwarding via tcp, suspending..."); + if(f->pMod->getWriteFDForSelect(f, f->pModData, &fdMod) == RS_RET_OK) { + if(FD_ISSET(f->f_file, &writefds)) { + if((iRet = f->pMod->onSelectReadyWrite(f, f->pModData)) != RS_RET_OK) { + dprintf("error %d from onSelectReadyWrite() - continuing\n", iRet); } - free(f->f_un.f_forw.savedMsg); - f->f_un.f_forw.savedMsg = NULL; } } } |