diff options
-rw-r--r-- | syslogd.c | 16 | ||||
-rw-r--r-- | threads.c | 14 | ||||
-rw-r--r-- | threads.h | 1 |
3 files changed, 27 insertions, 4 deletions
@@ -3491,9 +3491,8 @@ static void doDie(int sig) /* die() is called when the program shall end. This typically only occurs - * during sigterm or during the initialization. If you search for places where - * it is called, search for "die", not "die(", because the later will not find - * setting of signal handlers! As die() is intended to shutdown rsyslogd, it is + * during sigterm or during the initialization. + * As die() is intended to shutdown rsyslogd, it is * safe to call exit() here. Just make sure that die() itself is not called * at inapropriate places. As a general rule of thumb, it is a bad idea to add * any calls to die() in new code! @@ -3514,6 +3513,9 @@ static void die(int sig) logmsgInternal(LOG_SYSLOG|LOG_INFO, buf, ADDDATE); } + /* close the inputs */ + thrdTerminateAll(); /* TODO: inputs only, please */ + /* Free ressources and close connections */ freeSelectors(); @@ -4275,6 +4277,8 @@ init(void) eDfltHostnameCmpMode = HN_NO_COMP; Forwarding = 0; +dbgprintf("init()\n"); + thrdTerminateAll(); /* stop all running threads - TODO: reconsider location! */ #ifdef SYSLOG_INET if (restart) { if (pAllowedSenders_UDP != NULL) { @@ -6275,6 +6279,7 @@ int main(int argc, char **argv) usage(); checkPermissions(); + thrdInit(); if ( !(Debug || NoFork) ) { @@ -6437,9 +6442,12 @@ dbgprintf("joined thrdMain\n"); dbgprintf("reaching die\n"); die(bFinished); + + thrdExit(); return 0; } -/* vi:set ai: +/* + * vi:set ai: */ @@ -71,6 +71,7 @@ static rsRetVal thrdConstruct(thrdInfo_t **pThis) static rsRetVal thrdDestruct(thrdInfo_t *pThis) { assert(pThis != NULL); +dbgprintf("thrdDestruct, pThis: %lx\n", pThis); if(pThis->bIsActive == 1) { thrdTerminate(pThis); @@ -88,6 +89,7 @@ rsRetVal thrdTerminate(thrdInfo_t *pThis) { assert(pThis != NULL); +dbgprintf("Terminate thread %d via method %d\n", pThis->thrdID, pThis->eTermTool); if(pThis->eTermTool == eTermSync_SIGNAL) { pthread_kill(pThis->thrdID, SIGUSR2); pthread_join(pThis->thrdID, NULL); @@ -101,6 +103,17 @@ rsRetVal thrdTerminate(thrdInfo_t *pThis) } +/* terminate all known threads gracefully. + */ +rsRetVal thrdTerminateAll(void) +{ +dbgprintf("thrdTerminateAll in\n"); + llDestroy(&llThrds); +dbgprintf("thrdTerminateAll out\n"); + return RS_RET_OK; +} + + /* Start a new thread and add it to the list of currently * executing threads. It is added at the end of the list. * rgerhards, 2007-12-14 @@ -115,6 +128,7 @@ rsRetVal thrdCreate(void* (*thrdMain)(void*)) CHKiRet(thrdConstruct(&pThis)); i = pthread_create(&pThis->thrdID, NULL, thrdMain, NULL); + CHKiRet(llAppend(&llThrds, NULL, pThis)); finalize_it: return iRet; @@ -50,6 +50,7 @@ typedef struct { /* prototypes */ rsRetVal thrdTerminate(thrdInfo_t *pThis); +rsRetVal thrdTerminateAll(void); rsRetVal thrdCreate(void* (*thrdMain)(void*)); msgQueue *queueInit (void); void queueDelete (msgQueue *q); |