summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-07-26 08:42:14 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-07-26 08:42:14 +0000
commitc75d3b93480469abfd2cb8332bcc0e58c95ef5e3 (patch)
treec2e9041e09276e8960f2cc96b580b5cb78283376
parent229aa9e64424cf05fc2391ad2e7e2baefc37542f (diff)
downloadrsyslog-c75d3b93480469abfd2cb8332bcc0e58c95ef5e3.tar.gz
rsyslog-c75d3b93480469abfd2cb8332bcc0e58c95ef5e3.tar.xz
rsyslog-c75d3b93480469abfd2cb8332bcc0e58c95ef5e3.zip
- implemented onSelectReadyWrite() interface
- milestone reached: no more access to f->f_un in syslogd.c
-rw-r--r--module-template.h30
-rw-r--r--modules.c4
-rw-r--r--modules.h1
-rw-r--r--omdiscard.c8
-rw-r--r--omfile.c8
-rw-r--r--omfwd.c22
-rw-r--r--ommysql.c8
-rw-r--r--omshell.c8
-rw-r--r--omusrmsg.c8
-rw-r--r--syslogd.c24
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()
diff --git a/modules.c b/modules.c
index 445cbb36..067a7531 100644
--- a/modules.c
+++ b/modules.c
@@ -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;
diff --git a/modules.h b/modules.h
index 98256ea9..b2d040de 100644
--- a/modules.h
+++ b/modules.h
@@ -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
diff --git a/omfile.c b/omfile.c
index 6e03697e..ebd91fa1 100644
--- a/omfile.c
+++ b/omfile.c
@@ -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
diff --git a/omfwd.c b/omfwd.c
index 521d0597..44e1861e 100644
--- a/omfwd.c
+++ b/omfwd.c
@@ -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)
diff --git a/ommysql.c b/ommysql.c
index 877da4f7..e0e1f6da 100644
--- a/ommysql.c
+++ b/ommysql.c
@@ -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
diff --git a/omshell.c b/omshell.c
index 8b87a3fe..d341126c 100644
--- a/omshell.c
+++ b/omshell.c
@@ -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
diff --git a/omusrmsg.c b/omusrmsg.c
index 1613bb65..0b8eccc4 100644
--- a/omusrmsg.c
+++ b/omusrmsg.c
@@ -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
diff --git a/syslogd.c b/syslogd.c
index dae93362..d9d04bb2 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -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;
}
}
}