SMTP-Client: strip newlines from smtp replies when setting them as Statusmessage.
[citadel.git] / citadel / threads.c
index 965f866da2c31c44000988c8b3caf484c52d4aa3..062d19911870dc59c20660dfe4b6838c82041924 100644 (file)
@@ -157,6 +157,7 @@ void *CTC_backend(void *supplied_start_routine)
 
        start_routine(NULL);
 
+       free(mytsd);
        return(NULL);
 }
 
@@ -182,7 +183,10 @@ void InitializeMasterTSD(void) {
        memset(&masterTSD, 0, sizeof(struct thread_tsd));
 }
 
+extern void ShutDownEventQueues(void);
 
+int EventQShuttingDown = 0;
+int EVQShutDown = 0;
 /*
  * Initialize the thread system
  */
@@ -196,8 +200,6 @@ void go_threading(void)
        /* Second call to module init functions now that threading is up */
        initialise_modules(1);
 
-       CtdlThreadCreate(select_on_master);
-
        /* Begin with one worker thread.  We will expand the pool if necessary */
        CtdlThreadCreate(worker_thread);
 
@@ -208,18 +210,28 @@ void go_threading(void)
                if ((active_workers == num_workers) && (num_workers < 256)) {
                        CtdlThreadCreate(worker_thread);
                }
-               sleep(1);
+               usleep(1000);
        }
 
        /* When we get to this point we are getting ready to shut down our Citadel server */
+       if (!EventQShuttingDown)
+       {
+               EventQShuttingDown = 1;
+               ShutDownEventQueues();
+       }
+       while (!EVQShutDown)
+               usleep(1000);
+
 
        terminate_all_sessions();               /* close all client sockets */
        CtdlShutdownServiceHooks();             /* close all listener sockets to prevent new connections */
        PerformSessionHooks(EVT_SHUTDOWN);      /* run any registered shutdown hooks */
 
-       int countdown = 10;
+       int countdown = 30;
        while ( (num_workers > 0) && (countdown-- > 0)) {
-               syslog(LOG_DEBUG, "Waiting for %d worker threads to exit", num_workers);
-               sleep(1);
+               syslog(LOG_DEBUG, "Waiting %d seconds for %d worker threads to exit",
+                       countdown, num_workers
+               );
+               usleep(1000);
        }
 }