From de00dd2a7ea6202c2f154f2e3f4fd54e3cac32cc Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 9 Aug 2007 13:44:36 +0000 Subject: added module unload functionality; rsyslogd now unloads modules on exit (of course, with only statically linked modules, there is little current value in this - but it is made towards an upcoming dynaload plugin interface) --- modules.c | 21 +++++++++++++++++++++ modules.h | 1 + syslogd.c | 28 ++++++++++++++++------------ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/modules.c b/modules.c index 01bba104..5ecceecd 100644 --- a/modules.c +++ b/modules.c @@ -308,6 +308,27 @@ void modPrintList(void) } +/* unload all modules and free module linked list + * rgerhards, 2007-08-09 + */ +rsRetVal modUnloadAndDestructAll(void) +{ + DEFiRet; + modInfo_t *pMod; + modInfo_t *pModPrev; + + pMod = modGetNxt(NULL); + while(pMod != NULL) { + pModPrev = pMod; + pMod = modGetNxt(pModPrev); /* get next */ + /* now we can destroy the previous module */ + dbgprintf("Unloading module %s\n", modGetName(pModPrev)); + modUnload(pModPrev); + moduleDestruct(pModPrev); + } + + return iRet; +} /* * vi:set ai: */ diff --git a/modules.h b/modules.h index 7837f0fd..0fda461a 100644 --- a/modules.h +++ b/modules.h @@ -92,6 +92,7 @@ modInfo_t *omodGetNxt(modInfo_t *pThis); uchar *modGetName(modInfo_t *pThis); uchar *modGetStateName(modInfo_t *pThis); void modPrintList(void); +rsRetVal modUnloadAndDestructAll(void); #endif /* #ifndef MODULES_H_INCLUDED */ /* diff --git a/syslogd.c b/syslogd.c index b74bdb89..9cf51b34 100644 --- a/syslogd.c +++ b/syslogd.c @@ -3543,6 +3543,22 @@ static void die(int sig) remove_pid(PidFile); if(glblHadMemShortage) dbgprintf("Had memory shortage at least once during the run.\n"); + + /* de-init some modules */ + modExitIminternal(); + + /* TODO: this would also be the right place to de-init the builtin output modules. We + * do not currently do that, because the module interface does not allow for + * it. This will come some time later (it's essential with loadable modules). + * For the time being, this is a memory leak on exit, but as the process is + * terminated, we do not really bother about it. + * rgerhards, 2007-08-03 + * I have added some code now, but all that mod init/de-init should be moved to + * init, so that modules are unloaded and reloaded on HUP to. Eventually it should go + * into freeSelectors() - but that needs to be seen. -- rgerhards, 2007-08-09 + */ + modUnloadAndDestructAll(); + dbgprintf("Clean shutdown completed, bye.\n"); exit(0); /* "good" exit, this is the terminator function for rsyslog [die()] */ } @@ -6173,18 +6189,6 @@ int main(int argc, char **argv) */ mainloop(); - - /* de-init some modules */ - modExitIminternal(); - - /* TODO: this would also be the right place to de-init the builtin output modules. We - * do not currently do that, because the module interface does not allow for - * it. This will come some time later (it's essential with loadable modules). - * For the time being, this is a memory leak on exit, but as the process is - * terminated, we do not really bother about it. - * rgerhards, 2007-08-03 - */ - /* end de-init's */ die(bFinished); -- cgit