From: Dave West Date: Sat, 14 Nov 2009 16:17:06 +0000 (+0000) Subject: Fixed the SMTP sending as a thread. Now the thread doesn't think its X-Git-Tag: v7.86~618 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=c096beb42f81d5a2e0452b560ac08c29d5db8180;p=citadel.git Fixed the SMTP sending as a thread. Now the thread doesn't think its running when it isn't. --- diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index 3eb235b30..917ea5579 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -122,7 +122,7 @@ enum { /* Command states for login authentication */ int run_queue_now = 0; /* Set to 1 to ignore SMTP send retry times */ -/* citthread_mutex_t smtp_send_lock; */ +citthread_mutex_t smtp_send_lock; /*****************************************************************************/ @@ -1723,14 +1723,14 @@ void smtp_do_procmsg(long msgnum, void *userdata) { * * Run through the queue sending out messages. */ -void *smtp_do_queue(void /* *arg */) { +void *smtp_do_queue(void *arg) { int num_processed = 0; - /* struct CitContext smtp_queue_CC; */ + struct CitContext smtp_queue_CC; CtdlLogPrintf(CTDL_INFO, "SMTP client: processing outbound queue\n"); - /* CtdlFillSystemContext(&smtp_queue_CC, "SMTP Send"); - citthread_setspecific(MyConKey, (void *)&smtp_queue_CC ); */ + CtdlFillSystemContext(&smtp_queue_CC, "SMTP Send"); + citthread_setspecific(MyConKey, (void *)&smtp_queue_CC ); if (CtdlGetRoom(&CC->room, SMTP_SPOOLOUT_ROOM) != 0) { CtdlLogPrintf(CTDL_ERR, "Cannot find room <%s>\n", SMTP_SPOOLOUT_ROOM); @@ -1739,8 +1739,7 @@ void *smtp_do_queue(void /* *arg */) { num_processed = CtdlForEachMessage(MSGS_ALL, 0L, NULL, SPOOLMIME, NULL, smtp_do_procmsg, NULL); } - run_queue_now = 0; - /* citthread_mutex_unlock (&smtp_send_lock); */ + citthread_mutex_unlock (&smtp_send_lock); CtdlLogPrintf(CTDL_INFO, "SMTP client: queue run completed; %d messages processed\n", num_processed); return(NULL); } @@ -1760,25 +1759,25 @@ void *smtp_do_queue(void /* *arg */) { */ void smtp_queue_thread (void) { - /* - * if (citthread_mutex_trylock (&smtp_send_lock)) { - * CtdlLogPrintf(CTDL_DEBUG, "SMTP queue run already in progress\n"); - * } - * else { - * CtdlThreadCreate("SMTP Send", CTDLTHREAD_BIGSTACK, smtp_do_queue, NULL); - * } - */ - - static int queue_running = 0; /* The mutex locking isn't working. Gotta do this. */ - if (!queue_running) { - queue_running = 1; - smtp_do_queue(); - queue_running = 0; + if (citthread_mutex_trylock (&smtp_send_lock)) { + CtdlLogPrintf(CTDL_DEBUG, "SMTP queue run already in progress\n"); + } + else { + CtdlThreadCreate("SMTP Send", CTDLTHREAD_BIGSTACK, smtp_do_queue, NULL); } } +void smtp_server_going_down (void) +{ + CtdlLogPrintf(CTDL_DEBUG, "SMTP module clean up for shutdown.\n"); + + citthread_mutex_destroy (&smtp_send_lock); +} + + + /*****************************************************************************/ /* SMTP UTILITY COMMANDS */ /*****************************************************************************/ @@ -1859,7 +1858,6 @@ void smtp_cleanup_function(void) { CtdlLogPrintf(CTDL_DEBUG, "Performing SMTP cleanup hook\n"); free(SMTP); - /* citthread_mutex_destroy (&smtp_send_lock); */ } @@ -1915,7 +1913,8 @@ CTDL_MODULE_INIT(smtp) CtdlRegisterSessionHook(smtp_queue_thread, EVT_TIMER); CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP); CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands"); - /* citthread_mutex_init (&smtp_send_lock, NULL); */ + CtdlRegisterCleanupHook (smtp_server_going_down); + citthread_mutex_init (&smtp_send_lock, NULL); } /* return our Subversion id for the Log */