]> code.citadel.org Git - citadel.git/blobdiff - citadel/sysdep.c
* msgbase.c: when a summary mode message list is requested, and the room
[citadel.git] / citadel / sysdep.c
index 1380be84eb9a3dc89ef9559a7c25b27fac87dacd..5eac30ef3c1c4beb268710503eabf8716e92d9af 100644 (file)
  *
  */
 
-#ifdef DLL_EXPORT
-#define IN_LIBCIT
-#endif
-
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
@@ -66,6 +62,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 +94,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 +409,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 +533,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) {
@@ -581,7 +574,7 @@ void client_write(char *buf, int nbytes)
  */
 void cprintf(const char *format, ...) {   
        va_list arg_ptr;   
-       char buf[SIZ];   
+       char buf[1024];   
    
        va_start(arg_ptr, format);   
        if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
@@ -627,8 +620,7 @@ int client_read_to(char *buf, int bytes, int timeout)
 
                rlen = read(CC->client_socket, &buf[len], bytes-len);
                if (rlen<1) {
-                       lprintf(CTDL_ERR, "client_read() failed: %s\n",
-                               strerror(errno));
+                       /* The socket has been disconnected! */
                        CC->kill_me = 1;
                        return(-1);
                }
@@ -676,7 +668,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 +784,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 +809,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 +920,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.