summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules.c2
-rw-r--r--omdiscard.c15
-rw-r--r--omfile.c7
-rw-r--r--omfwd.c25
-rw-r--r--ommysql.c20
-rw-r--r--omshell.c15
-rw-r--r--omusrmsg.c15
-rw-r--r--syslogd.c176
8 files changed, 146 insertions, 129 deletions
diff --git a/modules.c b/modules.c
index 25f6b8cc..1565b31c 100644
--- a/modules.c
+++ b/modules.c
@@ -165,12 +165,10 @@ rsRetVal doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)()), uchar *name)
moduleDestruct(pNew);
return iRet;
}
-/* later...
if((iRet = (*pNew->modQueryEtryPt)((uchar*)"freeInstance", &pNew->freeInstance)) != RS_RET_OK) {
moduleDestruct(pNew);
return iRet;
}
-*/
pNew->pszName = (uchar*) strdup((char*)name); /* we do not care if strdup() fails, we can accept that */
pNew->eType = eMOD_OUT; /* TODO: take this from module */
diff --git a/omdiscard.c b/omdiscard.c
index 7db4a8d4..3d871133 100644
--- a/omdiscard.c
+++ b/omdiscard.c
@@ -53,6 +53,15 @@ static rsRetVal doAction(__attribute__((unused)) selector_t *f)
}
+/* free an instance
+ */
+static rsRetVal freeInstance(selector_t *f)
+{
+ assert(f != NULL);
+ return RS_RET_OK;
+}
+
+
/* try to process a selector action line. Checks if the action
* applies to this module and, if so, processed it. If not, it
* is left untouched. The driver will then call another module
@@ -94,9 +103,9 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())
*pEtryPoint = parseSelectorAct;
} else if(!strcmp((char*) name, "isCompatibleWithFeature")) {
*pEtryPoint = isCompatibleWithFeature;
- } /*else if(!strcmp((char*) name, "freeInstance")) {
- *pEtryPoint = freeInstanceFile;
- } */
+ } else if(!strcmp((char*) name, "freeInstance")) {
+ *pEtryPoint = freeInstance;
+ }
return(*pEtryPoint == NULL) ? RS_RET_NOT_FOUND : RS_RET_OK;
}
diff --git a/omfile.c b/omfile.c
index cb8061da..a5563c54 100644
--- a/omfile.c
+++ b/omfile.c
@@ -503,16 +503,15 @@ again:
/* free an instance
- * returns 0 if it succeeds, something else otherwise
*/
-rsRetVal freeInstanceFile(selector_t *f)
+static rsRetVal freeInstance(selector_t *f)
{
assert(f != NULL);
if(f->f_un.f_file.bDynamicName) {
dynaFileFreeCache(f);
} else
close(f->f_file);
- return 0;
+ return RS_RET_OK;
}
@@ -674,7 +673,7 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())
} else if(!strcmp((char*) name, "isCompatibleWithFeature")) {
*pEtryPoint = isCompatibleWithFeature;
} else if(!strcmp((char*) name, "freeInstance")) {
- *pEtryPoint = freeInstanceFile;
+ *pEtryPoint = freeInstance;
}
return(*pEtryPoint == NULL) ? RS_RET_NOT_FOUND : RS_RET_OK;
diff --git a/omfwd.c b/omfwd.c
index b9197e92..cffd4ac2 100644
--- a/omfwd.c
+++ b/omfwd.c
@@ -442,6 +442,25 @@ static rsRetVal parseSelectorAct(uchar **pp, selector_t *f)
return iRet;
}
+/* free an instance
+ */
+static rsRetVal freeInstance(selector_t *f)
+{
+ assert(f != NULL);
+ switch (f->f_type) {
+ case F_FORW:
+ case F_FORW_SUSP:
+ freeaddrinfo(f->f_un.f_forw.f_addr);
+ /* fall through */
+ case F_FORW_UNKN:
+ if(f->f_un.f_forw.port != NULL)
+ free(f->f_un.f_forw.port);
+ break;
+ }
+ return RS_RET_OK;
+}
+
+
/* query an entry point
*/
static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())
@@ -456,9 +475,9 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())
*pEtryPoint = parseSelectorAct;
} else if(!strcmp((char*) name, "isCompatibleWithFeature")) {
*pEtryPoint = isCompatibleWithFeature;
- } /*else if(!strcmp((char*) name, "freeInstance")) {
- *pEtryPoint = freeInstanceFile;
- }*/
+ } else if(!strcmp((char*) name, "freeInstance")) {
+ *pEtryPoint = freeInstance;
+ }
return(*pEtryPoint == NULL) ? RS_RET_NOT_FOUND : RS_RET_OK;
}
diff --git a/ommysql.c b/ommysql.c
index 37ec0b22..509d5b39 100644
--- a/ommysql.c
+++ b/ommysql.c
@@ -389,6 +389,20 @@ static rsRetVal parseSelectorAct(uchar **pp, selector_t *f)
return iRet;
}
+
+/* free an instance
+ */
+static rsRetVal freeInstance(selector_t *f)
+{
+ assert(f != NULL);
+ switch (f->f_type) {
+# ifdef WITH_DB
+ closeMySQL(f);
+# endif
+ }
+ return RS_RET_OK;
+}
+
/* query an entry point
*/
static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())
@@ -403,9 +417,9 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())
*pEtryPoint = parseSelectorAct;
} else if(!strcmp((char*) name, "isCompatibleWithFeature")) {
*pEtryPoint = isCompatibleWithFeature;
- } /*else if(!strcmp((char*) name, "freeInstance")) {
- *pEtryPoint = freeInstanceFile;
- }*/
+ } else if(!strcmp((char*) name, "freeInstance")) {
+ *pEtryPoint = freeInstance;
+ }
return(*pEtryPoint == NULL) ? RS_RET_NOT_FOUND : RS_RET_OK;
}
diff --git a/omshell.c b/omshell.c
index 80bec178..df9da9f5 100644
--- a/omshell.c
+++ b/omshell.c
@@ -109,6 +109,15 @@ static rsRetVal parseSelectorAct(uchar **pp, selector_t *f)
return iRet;
}
+
+/* free an instance
+ */
+static rsRetVal freeInstance(selector_t *f)
+{
+ assert(f != NULL);
+ return RS_RET_OK;
+}
+
/* query an entry point
*/
static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())
@@ -123,9 +132,9 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())
*pEtryPoint = parseSelectorAct;
} else if(!strcmp((char*) name, "isCompatibleWithFeature")) {
*pEtryPoint = isCompatibleWithFeature;
- } /*else if(!strcmp((char*) name, "freeInstance")) {
- *pEtryPoint = freeInstanceFile;
- } */
+ } else if(!strcmp((char*) name, "freeInstance")) {
+ *pEtryPoint = freeInstance;
+ }
return(*pEtryPoint == NULL) ? RS_RET_NOT_FOUND : RS_RET_OK;
}
diff --git a/omusrmsg.c b/omusrmsg.c
index 5f743eff..196738e6 100644
--- a/omusrmsg.c
+++ b/omusrmsg.c
@@ -307,6 +307,15 @@ static rsRetVal parseSelectorAct(uchar **pp, selector_t *f)
return iRet;
}
+
+/* free an instance
+ */
+static rsRetVal freeInstance(selector_t *f)
+{
+ assert(f != NULL);
+ return RS_RET_OK;
+}
+
/* query an entry point
*/
static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())
@@ -321,9 +330,9 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())
*pEtryPoint = parseSelectorAct;
} else if(!strcmp((char*) name, "isCompatibleWithFeature")) {
*pEtryPoint = isCompatibleWithFeature;
- } /*else if(!strcmp((char*) name, "freeInstance")) {
- *pEtryPoint = freeInstanceFile;
- }*/
+ } else if(!strcmp((char*) name, "freeInstance")) {
+ *pEtryPoint = freeInstance;
+ }
return(*pEtryPoint == NULL) ? RS_RET_NOT_FOUND : RS_RET_OK;
}
diff --git a/syslogd.c b/syslogd.c
index e5dbd2d1..d2c57cbf 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -672,6 +672,7 @@ static rsRetVal cfline(char *line, register selector_t *f);
static int decode(uchar *name, struct code *codetab);
static void sighup_handler();
static void die(int sig);
+static void freeSelectors(void);
/* Access functions for the selector_t. These functions are primarily
* necessary to make things thread-safe. Consequently, they are slim
@@ -3487,7 +3488,7 @@ static void doDie(int sig)
*/
static void die(int sig)
{
- register selector_t *f, *fPrev;
+ register selector_t *f;
char buf[256];
int i;
int was_initialized = Initialized;
@@ -3520,43 +3521,10 @@ static void die(int sig)
#endif
- /* Free ressources and close MySQL connections */
- for (f = Files; f != NULL ;) {
- /* free iovec if it was allocated */
- if(f->f_iov != NULL) {
- if(f->f_bMustBeFreed != NULL) {
- iovDeleteFreeableStrings(f);
- free(f->f_bMustBeFreed);
- }
- free(f->f_iov);
- }
- /* Now delete cached messages */
- if(f->f_pMsg != NULL)
- MsgDestruct(f->f_pMsg);
-#ifdef WITH_DB
- if (f->f_type == F_MYSQL)
- closeMySQL(f);
-#endif
- switch (f->f_type) {
- case F_FORW:
- case F_FORW_SUSP:
- freeaddrinfo(f->f_un.f_forw.f_addr);
- /* fall through */
- case F_FORW_UNKN:
- if (f->f_un.f_forw.port != NULL)
- free(f->f_un.f_forw.port);
- }
-
- if (f->f_psziov != NULL)
- free(f->f_psziov);
-
- fPrev = f;
- f = f->f_next;
- free(fPrev);
- }
+ /* Free ressources and close connections */
+ freeSelectors();
/* now clean up the listener part */
-
#ifdef SYSLOG_INET
/* Close the UNIX sockets. */
for (i = 0; i < nfunix; i++)
@@ -4146,6 +4114,63 @@ void cfsysline(uchar *p)
}
+/* Close all open log files and free selector descriptor array.
+ */
+static void freeSelectors(void)
+{
+ selector_t *f;
+ selector_t *fPrev;
+
+ Initialized = 0;
+ if(Files != NULL) {
+ dprintf("Freeing log structures.\n");
+
+ f = Files;
+ while (f != NULL) {
+ /* flush any pending output */
+ if (f->f_prevcount) {
+ fprintlog(f);
+ }
+
+ /* free iovec if it was allocated */
+ if(f->f_iov != NULL) {
+ if(f->f_bMustBeFreed != NULL) {
+ iovDeleteFreeableStrings(f);
+ free(f->f_bMustBeFreed);
+ }
+ free(f->f_iov);
+ }
+
+ /* free iov string */
+ if (f->f_psziov != NULL)
+ free(f->f_psziov);
+
+ /* free the action instances */
+ f->pMod->freeInstance(f);
+# ifdef USE_PTHREADS
+ /* delete any mutex objects, if present */
+ if( ( (f->f_type == F_FORW_SUSP)
+ || (f->f_type == F_FORW)
+ || (f->f_type == F_FORW_UNKN) )
+ && (f->f_un.f_forw.protocol == FORW_TCP)) {
+ pthread_mutex_destroy(&f->f_un.f_forw.mtxTCPSend);
+ }
+# endif
+ if(f->f_pMsg != NULL)
+ MsgDestruct(f->f_pMsg);
+
+ /* done with this entry, we now need to delete itself */
+ fPrev = f;
+ f = f->f_next;
+ free(fPrev);
+ }
+
+ /* Reflect the deletion of the selectors linked list. */
+ Files = NULL;
+ }
+}
+
+
/* INIT -- Initialize syslogd from configuration table
* init() is called at initial startup AND each time syslogd is HUPed
*/
@@ -4216,86 +4241,20 @@ static void init()
}
}
- /* Close all open log files and free log descriptor array.
- */
dprintf("Called init.\n");
- Initialized = 0;
- if(Files != NULL) {
- selector_t *fPrev;
- dprintf("Initializing log structures.\n");
-
- f = Files;
- while (f != NULL) {
- /* flush any pending output */
- if (f->f_prevcount) {
- fprintlog(f);
- }
-
- /* free iovec if it was allocated */
- if(f->f_iov != NULL) {
- if(f->f_bMustBeFreed != NULL) {
- iovDeleteFreeableStrings(f);
- free(f->f_bMustBeFreed);
- }
- free(f->f_iov);
- }
- /* free iov string */
- if (f->f_psziov != NULL)
- free(f->f_psziov);
-
- switch (f->f_type) {
- case F_FILE:
- case F_PIPE:
- case F_TTY:
- case F_CONSOLE:
- freeInstanceFile(f);
- break;
- case F_FORW:
- case F_FORW_SUSP:
- freeaddrinfo(f->f_un.f_forw.f_addr);
- /* fall through */
- case F_FORW_UNKN:
- if(f->f_un.f_forw.port != NULL)
- free(f->f_un.f_forw.port);
- break;
-# ifdef WITH_DB
- case F_MYSQL:
- closeMySQL(f);
- break;
-# endif
- }
-# ifdef USE_PTHREADS
- /* delete any mutex objects, if present */
- if( ( (f->f_type == F_FORW_SUSP)
- || (f->f_type == F_FORW)
- || (f->f_type == F_FORW_UNKN) )
- && (f->f_un.f_forw.protocol == FORW_TCP)) {
- pthread_mutex_destroy(&f->f_un.f_forw.mtxTCPSend);
- }
-# endif
- if(f->f_pMsg != NULL)
- MsgDestruct(f->f_pMsg);
-
- /* done with this entry, we now need to delete itself */
- fPrev = f;
- f = f->f_next;
- free(fPrev);
- }
-
- /* Reflect the deletion of the Files linked list. */
- Files = NULL;
- }
+ /* Close all open log files and free log descriptor array. */
+ freeSelectors();
dprintf("Clearing templates.\n");
tplDeleteNew();
- f = NULL;
- nextp = NULL;
-
/* re-setting values to defaults (where applicable) */
resetConfigVariables();
+ f = NULL;
+ nextp = NULL;
+
/* open the configuration file */
if ((cf = fopen(ConfFile, "r")) == NULL) {
/* rgerhards: this code is executed to set defaults when the
@@ -5792,7 +5751,8 @@ int main(int argc, char **argv)
uchar *pTmp;
#ifndef TESTING
- chdir ("/");
+ if(chdir ("/") != 0)
+ fprintf(stderr, "Can not do 'cd /' - still trying to run\n");
#endif
for (i = 1; i < MAXFUNIX; i++) {
funixn[i] = "";