]> code.citadel.org Git - citadel.git/blobdiff - citadel/sysdep.c
* There is now a dedicated thread for doing database checkpoints.
[citadel.git] / citadel / sysdep.c
index c6c96ac09a6f74554a56d8ac275f94f2550d8a80..1179ea604fcee87a6c8a8f6ae77ee7fec0db7428 100644 (file)
@@ -66,6 +66,7 @@
 #include "housekeeping.h"
 #include "tools.h"
 #include "serv_crypto.h"
+#include "serv_fulltext.h"
 
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
@@ -97,6 +98,8 @@ struct CitContext masterCC;
 time_t last_purge = 0;                         /* Last dead session purge */
 static int num_threads = 0;                    /* Current number of threads */
 int num_sessions = 0;                          /* Current number of sessions */
+pthread_t indexer_thread_tid;
+pthread_t checkpoint_thread_tid;
 
 int syslog_facility = (-1);
 int enable_syslog = 0;
@@ -410,8 +413,7 @@ struct CitContext *MyContext(void) {
  * Initialize a new context and place it in the list.  The session number
  * used to be the PID (which is why it's called cs_pid), but that was when we
  * had one process per session.  Now we just assign them sequentially, starting
- * at 1 (don't change it to 0 because masterCC uses 0) and re-using them when
- * sessions terminate.
+ * at 1 (don't change it to 0 because masterCC uses 0).
  */
 struct CitContext *CreateNewContext(void) {
        struct CitContext *me;
@@ -535,11 +537,6 @@ void client_write(char *buf, int nbytes)
                return;
        }
 
-       if (CC->redirect_fp != NULL) {
-               fwrite(buf, (size_t)nbytes, (size_t)1, CC->redirect_fp);
-               return;
-       }
-
 #ifndef HAVE_TCP_BUFFERING
        /* If we're buffering for later, do that now. */
        if (CC->buffering) {
@@ -676,7 +673,7 @@ int client_getln(char *buf, int bufsize)
        buf[i] = 0;
        while ((strlen(buf)>0)&&(!isprint(buf[strlen(buf)-1])))
                buf[strlen(buf)-1] = 0;
-       if (retval < 0) strcpy(buf, "000");
+       if (retval < 0) safestrncpy(buf, "000", bufsize);
        return(retval);
 }
 
@@ -792,12 +789,13 @@ void create_worker(void) {
                return;
        }
 
-       /* Our per-thread stacks need to be bigger than the default size, otherwise
-        * the MIME parser crashes on FreeBSD, and the IMAP service crashes on
-        * 64-bit Linux.
+       /* Our per-thread stacks need to be bigger than the default size,
+        * otherwise the MIME parser crashes on FreeBSD, and the IMAP service
+        * crashes on 64-bit Linux.
         */
-       if ((ret = pthread_attr_setstacksize(&attr, 1024 * 1024))) {
-               lprintf(CTDL_EMERG, "pthread_attr_setstacksize: %s\n", strerror(ret));
+       if ((ret = pthread_attr_setstacksize(&attr, THREADSTACKSIZE))) {
+               lprintf(CTDL_EMERG, "pthread_attr_setstacksize: %s\n",
+                       strerror(ret));
                time_to_die = -1;
                pthread_attr_destroy(&attr);
                return;
@@ -816,6 +814,44 @@ void create_worker(void) {
 }
 
 
+/*
+ * Create the indexer thread and begin its operation.
+ * Then create the checkpoint thread and begin its operation.
+ */
+void create_maintenance_threads(void) {
+       int ret;
+       pthread_attr_t attr;
+
+       if ((ret = pthread_attr_init(&attr))) {
+               lprintf(CTDL_EMERG, "pthread_attr_init: %s\n", strerror(ret));
+               time_to_die = -1;
+               return;
+       }
+
+       /* Our per-thread stacks need to be bigger than the default size,
+        * otherwise the MIME parser crashes on FreeBSD, and the IMAP service
+        * crashes on 64-bit Linux.
+        */
+       if ((ret = pthread_attr_setstacksize(&attr, THREADSTACKSIZE))) {
+               lprintf(CTDL_EMERG, "pthread_attr_setstacksize: %s\n",
+                       strerror(ret));
+               time_to_die = -1;
+               pthread_attr_destroy(&attr);
+               return;
+       }
+
+       if ((ret = pthread_create(&indexer_thread_tid, &attr, indexer_thread, NULL) != 0)) {
+               lprintf(CTDL_ALERT, "Can't create thread: %s\n", strerror(ret));
+       }
+
+       if ((ret = pthread_create(&checkpoint_thread_tid, &attr, checkpoint_thread, NULL) != 0)) {
+               lprintf(CTDL_ALERT, "Can't create thread: %s\n", strerror(ret));
+       }
+
+       pthread_attr_destroy(&attr);
+}
+
+
 
 /*
  * Purge all sessions which have the 'kill_me' flag set.
@@ -889,18 +925,6 @@ void dead_session_purge(int force) {
 
 
 
-/*
- * Redirect a session's output to a file.
- * This function may be called with a file handle.
- * Call with NULL to return output to its normal client socket.
- */
-void CtdlRedirectOutput(FILE *fp)
-{
-       if (fp != NULL) CC->redirect_fp = fp;
-       else CC->redirect_fp = NULL;
-}
-
-
 /*
  * masterCC is the context we use when not attached to a session.  This
  * function initializes it.