diff options
-rw-r--r-- | modules.c | 2 | ||||
-rw-r--r-- | omdiscard.c | 15 | ||||
-rw-r--r-- | omfile.c | 7 | ||||
-rw-r--r-- | omfwd.c | 25 | ||||
-rw-r--r-- | ommysql.c | 20 | ||||
-rw-r--r-- | omshell.c | 15 | ||||
-rw-r--r-- | omusrmsg.c | 15 | ||||
-rw-r--r-- | syslogd.c | 176 |
8 files changed, 146 insertions, 129 deletions
@@ -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; } @@ -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; @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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] = ""; |